Skip to content

Commit 87ab65e

Browse files
dfa1claude
andcommitted
refactor(reader): rename Array.truncate -> limited
"truncate" reads as "empty the array" (SQL TRUNCATE, file truncate-to-0); the operation keeps the first N rows. Rename to limited(rows) across the hierarchy and unify the prior naming drift: - Array.truncate -> limited; static guard Array.truncated -> Array.limited - all family-interface defaults + Chunked/Null/Masked/Decimal overrides - VarBinArray.truncate -> limited - GenericArray.withLength folded into limited (single method) - ChunkedArrays.truncateChildren -> limitedChildren - ScanIterator.truncateColumns -> limitedColumns - tests updated Pure rename; no behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 683d6a0 commit 87ab65e

27 files changed

Lines changed: 69 additions & 73 deletions

reader/src/main/java/io/github/dfa1/vortex/reader/ScanIterator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ private static long readUnsigned(MemorySegment seg, long idx, PType ptype) {
257257

258258
// ── Zone-map pruning ──────────────────────────────────────────────────────
259259

260-
private static Map<String, Array> truncateColumns(Map<String, Array> columns, long rows) {
260+
private static Map<String, Array> limitedColumns(Map<String, Array> columns, long rows) {
261261
var result = new LinkedHashMap<String, Array>(columns.size());
262262
for (var entry : columns.entrySet()) {
263-
result.put(entry.getKey(), Array.truncated(entry.getValue(), rows));
263+
result.put(entry.getKey(), Array.limited(entry.getValue(), rows));
264264
}
265265
return Map.copyOf(result);
266266
}
@@ -312,7 +312,7 @@ public Chunk next() {
312312
try {
313313
Map<String, Array> columns = buildColumnMap(spec, arena);
314314
if (chunkRows < spec.rowCount()) {
315-
columns = truncateColumns(columns, chunkRows);
315+
columns = limitedColumns(columns, chunkRows);
316316
}
317317
rowsReturned += chunkRows;
318318
Map<String, DType> chunkDtypes = new java.util.LinkedHashMap<>();

reader/src/main/java/io/github/dfa1/vortex/reader/array/Array.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ public sealed interface Array
2828
///
2929
/// Used by the scan layer to honour [io.github.dfa1.vortex.reader.ScanOptions]
3030
/// row limits. Callers must guarantee `rows < length()` — use the
31-
/// [#truncated(Array, long)] guard, which short-circuits the no-op case.
31+
/// [#limited(Array, long)] guard, which short-circuits the no-op case.
3232
///
3333
/// The primitive family interfaces ([LongArray], [IntArray], …) provide a
3434
/// zero-copy default: a length-capping view over `this` (no buffer is copied).
3535
/// Subtypes that can do better override it — chunked arrays keep their whole
36-
/// prefix children and only truncate the boundary child, preserving batch
36+
/// prefix children and only limited the boundary child, preserving batch
3737
/// iteration. The base default fails fast for types with no truncation support
3838
/// (struct, list, …).
3939
///
4040
/// @param rows number of leading elements to keep; must be `< length()`
4141
/// @return a new array of length `rows`
4242
/// @throws VortexException if truncation is not supported for this array type
43-
default Array truncate(long rows) {
43+
default Array limited(long rows) {
4444
throw new VortexException("limit: truncation not supported for " + getClass().getSimpleName());
4545
}
4646

@@ -49,10 +49,10 @@ default Array truncate(long rows) {
4949
/// recurse into children, so the `rows >= length()` no-op is handled in exactly
5050
/// one place.
5151
///
52-
/// @param arr array to truncate
52+
/// @param arr array to limited
5353
/// @param rows desired length
54-
/// @return `arr` when `arr.length() <= rows`, otherwise `arr.truncate(rows)`
55-
static Array truncated(Array arr, long rows) {
56-
return arr.length() <= rows ? arr : arr.truncate(rows);
54+
/// @return `arr` when `arr.length() <= rows`, otherwise `arr.limited(rows)`
55+
static Array limited(Array arr, long rows) {
56+
return arr.length() <= rows ? arr : arr.limited(rows);
5757
}
5858
}

reader/src/main/java/io/github/dfa1/vortex/reader/array/BoolArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ default void forEachBoolean(BooleanConsumer c) {
2929
/// @param rows number of leading elements to keep
3030
/// @return a length-`rows` bool array view
3131
@Override
32-
default Array truncate(long rows) {
32+
default Array limited(long rows) {
3333
return new OffsetBoolArray(dtype(), rows, this, 0);
3434
}
3535
}

reader/src/main/java/io/github/dfa1/vortex/reader/array/ByteArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ default void forEachByte(ByteConsumer c) {
5050
/// @param rows number of leading elements to keep
5151
/// @return a length-`rows` byte array view
5252
@Override
53-
default Array truncate(long rows) {
53+
default Array limited(long rows) {
5454
return new OffsetByteArray(dtype(), rows, this, 0);
5555
}
5656
}

reader/src/main/java/io/github/dfa1/vortex/reader/array/ChunkedArrays.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/// Shared helper for the `ChunkedXxxArray.truncate` overrides. Keeps whole prefix
7-
/// children that fit within `rows` and recursively truncates the single boundary
6+
/// Shared helper for the `ChunkedXxxArray.limited` overrides. Keeps whole prefix
7+
/// children that fit within `rows` and recursively limits the single boundary
88
/// child — preserving each chunk's batch iteration / zero-copy backing instead of
99
/// the per-element view a plain length-cap would impose.
1010
final class ChunkedArrays {
@@ -17,8 +17,8 @@ private ChunkedArrays() {
1717
/// @param children chunk arrays in scan order
1818
/// @param offsets cumulative row offsets (length = `children.length + 1`)
1919
/// @param rows number of leading rows to keep
20-
/// @return prefix children unchanged, with the boundary child truncated
21-
static List<Array> truncateChildren(Array[] children, long[] offsets, long rows) {
20+
/// @return prefix children unchanged, with the boundary child limited
21+
static List<Array> limitedChildren(Array[] children, long[] offsets, long rows) {
2222
var kept = new ArrayList<Array>(children.length);
2323
for (int i = 0; i < children.length; i++) {
2424
long start = offsets[i];
@@ -29,7 +29,7 @@ static List<Array> truncateChildren(Array[] children, long[] offsets, long rows)
2929
if (end <= rows) {
3030
kept.add(children[i]);
3131
} else {
32-
kept.add(Array.truncated(children[i], rows - start));
32+
kept.add(Array.limited(children[i], rows - start));
3333
}
3434
}
3535
return kept;

reader/src/main/java/io/github/dfa1/vortex/reader/array/ChunkedBoolArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void forEachBoolean(BooleanConsumer c) {
7272
}
7373

7474
@Override
75-
public Array truncate(long rows) {
76-
return ChunkedBoolArray.of(dtype, rows, ChunkedArrays.truncateChildren(children, offsets, rows));
75+
public Array limited(long rows) {
76+
return ChunkedBoolArray.of(dtype, rows, ChunkedArrays.limitedChildren(children, offsets, rows));
7777
}
7878
}

reader/src/main/java/io/github/dfa1/vortex/reader/array/ChunkedByteArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void forEachByte(ByteConsumer c) {
8484
}
8585

8686
@Override
87-
public Array truncate(long rows) {
88-
return ChunkedByteArray.of(dtype, rows, ChunkedArrays.truncateChildren(children, offsets, rows));
87+
public Array limited(long rows) {
88+
return ChunkedByteArray.of(dtype, rows, ChunkedArrays.limitedChildren(children, offsets, rows));
8989
}
9090
}

reader/src/main/java/io/github/dfa1/vortex/reader/array/ChunkedDoubleArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public double fold(double identity, DoubleBinaryOperator op) {
8181
}
8282

8383
@Override
84-
public Array truncate(long rows) {
85-
return ChunkedDoubleArray.of(dtype, rows, ChunkedArrays.truncateChildren(children, offsets, rows));
84+
public Array limited(long rows) {
85+
return ChunkedDoubleArray.of(dtype, rows, ChunkedArrays.limitedChildren(children, offsets, rows));
8686
}
8787
}

reader/src/main/java/io/github/dfa1/vortex/reader/array/ChunkedFloatArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public double fold(double identity, DoubleBinaryOperator op) {
7171
}
7272

7373
@Override
74-
public Array truncate(long rows) {
75-
return ChunkedFloatArray.of(dtype, rows, ChunkedArrays.truncateChildren(children, offsets, rows));
74+
public Array limited(long rows) {
75+
return ChunkedFloatArray.of(dtype, rows, ChunkedArrays.limitedChildren(children, offsets, rows));
7676
}
7777
}

reader/src/main/java/io/github/dfa1/vortex/reader/array/ChunkedIntArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public int fold(int identity, IntBinaryOperator op) {
7979
}
8080

8181
@Override
82-
public Array truncate(long rows) {
83-
return ChunkedIntArray.of(dtype, rows, ChunkedArrays.truncateChildren(children, offsets, rows));
82+
public Array limited(long rows) {
83+
return ChunkedIntArray.of(dtype, rows, ChunkedArrays.limitedChildren(children, offsets, rows));
8484
}
8585
}

0 commit comments

Comments
 (0)