Skip to content

Commit 88a6663

Browse files
dfa1claude
andcommitted
refactor(writer-test): extract VortexReads helper
readAllInts / readAllLongs / readAllStrings were copy-pasted across BitpackedEncodingTest, DeltaEncodingTest, DictEncodingTest, and GlobalDictUtf8Test. Move into a package-private VortexReads util with the matching LE_INT / LE_LONG constants, drop the duplicates. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 0704b68 commit 88a6663

5 files changed

Lines changed: 69 additions & 75 deletions

File tree

‎writer/src/test/java/io/github/dfa1/vortex/writer/BitpackedEncodingTest.java‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,31 @@
22

33
import io.github.dfa1.vortex.core.DType;
44
import io.github.dfa1.vortex.core.PType;
5-
import io.github.dfa1.vortex.core.array.Array;
6-
import io.github.dfa1.vortex.core.array.ArraySegments;
75
import io.github.dfa1.vortex.encoding.BitpackedEncoding;
86
import io.github.dfa1.vortex.encoding.Registry;
97
import io.github.dfa1.vortex.reader.VortexReader;
10-
import io.github.dfa1.vortex.reader.ScanOptions;
118
import org.junit.jupiter.api.Test;
129
import org.junit.jupiter.api.io.TempDir;
1310
import org.junit.jupiter.params.ParameterizedTest;
1411
import org.junit.jupiter.params.provider.ValueSource;
1512

1613
import java.io.IOException;
17-
import java.lang.foreign.ValueLayout;
18-
import java.nio.ByteOrder;
1914
import java.nio.channels.FileChannel;
2015
import java.nio.file.Path;
2116
import java.nio.file.StandardOpenOption;
22-
import java.util.ArrayList;
2317
import java.util.List;
2418
import java.util.Map;
2519

20+
import static io.github.dfa1.vortex.writer.VortexReads.readAllInts;
2621
import static org.assertj.core.api.Assertions.assertThat;
2722

2823
class BitpackedEncodingTest {
2924

30-
private static final ValueLayout.OfInt LE_INT = ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
3125
private static final DType.Struct I32_SCHEMA = new DType.Struct(
3226
List.of("value"),
3327
List.of(new DType.Primitive(PType.I32, false)),
3428
false);
3529

36-
/// Materializes every chunk of the named I32 column into a primitive int[] by
37-
/// copying values out of the per-chunk arena before each [io.github.dfa1.vortex.reader.Chunk]
38-
/// closes. Returns a heap array independent of the scan lifecycle.
39-
private static int[] readAllInts(VortexReader vf, String col) {
40-
var collected = new ArrayList<Integer>();
41-
try (var iter = vf.scan(ScanOptions.all())) {
42-
iter.forEachRemaining(c -> {
43-
Array arr = c.column(col);
44-
for (long i = 0; i < arr.length(); i++) {
45-
collected.add(ArraySegments.of(arr).get(LE_INT, i * Integer.BYTES));
46-
}
47-
});
48-
}
49-
return collected.stream().mapToInt(Integer::intValue).toArray();
50-
}
51-
5230
private static Registry bitpackedRegistry() {
5331
return Registry.builder().register(new BitpackedEncoding()).build();
5432
}

‎writer/src/test/java/io/github/dfa1/vortex/writer/DeltaEncodingTest.java‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,31 @@
22

33
import io.github.dfa1.vortex.core.DType;
44
import io.github.dfa1.vortex.core.PType;
5-
import io.github.dfa1.vortex.core.array.Array;
6-
import io.github.dfa1.vortex.core.array.ArraySegments;
75
import io.github.dfa1.vortex.encoding.DeltaEncoding;
86
import io.github.dfa1.vortex.encoding.Registry;
97
import io.github.dfa1.vortex.reader.VortexReader;
10-
import io.github.dfa1.vortex.reader.ScanOptions;
118
import org.junit.jupiter.api.Test;
129
import org.junit.jupiter.api.io.TempDir;
1310
import org.junit.jupiter.params.ParameterizedTest;
1411
import org.junit.jupiter.params.provider.ValueSource;
1512

1613
import java.io.IOException;
17-
import java.lang.foreign.ValueLayout;
18-
import java.nio.ByteOrder;
1914
import java.nio.channels.FileChannel;
2015
import java.nio.file.Path;
2116
import java.nio.file.StandardOpenOption;
22-
import java.util.ArrayList;
2317
import java.util.List;
2418
import java.util.Map;
2519

20+
import static io.github.dfa1.vortex.writer.VortexReads.readAllLongs;
2621
import static org.assertj.core.api.Assertions.assertThat;
2722

2823
class DeltaEncodingTest {
2924

30-
private static final ValueLayout.OfLong LE_LONG = ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
3125
private static final DType.Struct I64_SCHEMA = new DType.Struct(
3226
List.of("ts"),
3327
List.of(new DType.Primitive(PType.I64, false)),
3428
false);
3529

36-
private static long[] readAllLongs(VortexReader vf, String col) {
37-
var collected = new ArrayList<Long>();
38-
try (var iter = vf.scan(ScanOptions.all())) {
39-
iter.forEachRemaining(c -> {
40-
Array arr = c.column(col);
41-
for (long i = 0; i < arr.length(); i++) {
42-
collected.add(ArraySegments.of(arr).get(LE_LONG, i * Long.BYTES));
43-
}
44-
});
45-
}
46-
return collected.stream().mapToLong(Long::longValue).toArray();
47-
}
48-
4930
private static Registry deltaRegistry() {
5031
return Registry.builder()
5132
.register(new DeltaEncoding())

‎writer/src/test/java/io/github/dfa1/vortex/writer/DictEncodingTest.java‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import java.nio.channels.FileChannel;
2020
import java.nio.file.Path;
2121
import java.nio.file.StandardOpenOption;
22-
import java.util.ArrayList;
2322
import java.util.List;
2423
import java.util.Map;
2524

25+
import static io.github.dfa1.vortex.writer.VortexReads.readAllInts;
2626
import static org.assertj.core.api.Assertions.assertThat;
2727

2828
class DictEncodingTest {
@@ -33,19 +33,6 @@ class DictEncodingTest {
3333
List.of(new DType.Primitive(PType.I32, false)),
3434
false);
3535

36-
private static int[] readAllInts(VortexReader vf, String col) {
37-
var collected = new ArrayList<Integer>();
38-
try (var iter = vf.scan(ScanOptions.all())) {
39-
iter.forEachRemaining(c -> {
40-
Array arr = c.column(col);
41-
for (long i = 0; i < arr.length(); i++) {
42-
collected.add(ArraySegments.of(arr).get(LE_INT, i * Integer.BYTES));
43-
}
44-
});
45-
}
46-
return collected.stream().mapToInt(Integer::intValue).toArray();
47-
}
48-
4936
private static Registry dictRegistry() {
5037
return Registry.builder()
5138
.register(new DictEncoding())

‎writer/src/test/java/io/github/dfa1/vortex/writer/GlobalDictUtf8Test.java‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package io.github.dfa1.vortex.writer;
22

33
import io.github.dfa1.vortex.core.DType;
4-
import io.github.dfa1.vortex.core.array.Array;
5-
import io.github.dfa1.vortex.core.array.VarBinArray;
64
import io.github.dfa1.vortex.encoding.Registry;
75
import io.github.dfa1.vortex.reader.VortexReader;
8-
import io.github.dfa1.vortex.reader.ScanOptions;
96
import org.junit.jupiter.api.Test;
107
import org.junit.jupiter.api.io.TempDir;
118

@@ -14,10 +11,10 @@
1411
import java.nio.file.Files;
1512
import java.nio.file.Path;
1613
import java.nio.file.StandardOpenOption;
17-
import java.util.ArrayList;
1814
import java.util.List;
1915
import java.util.Map;
2016

17+
import static io.github.dfa1.vortex.writer.VortexReads.readAllStrings;
2118
import static org.assertj.core.api.Assertions.assertThat;
2219

2320
/// Global dictionary encoding for low-cardinality Utf8 columns: one dict shared
@@ -29,20 +26,6 @@ class GlobalDictUtf8Test {
2926
List.of(new DType.Utf8(false)),
3027
false);
3128

32-
private static List<String> readAllStrings(VortexReader vf, String col) {
33-
var collected = new ArrayList<String>();
34-
try (var iter = vf.scan(ScanOptions.all())) {
35-
iter.forEachRemaining(c -> {
36-
Array arr = c.column(col);
37-
VarBinArray vb = (VarBinArray) arr;
38-
for (long i = 0; i < vb.length(); i++) {
39-
collected.add(vb.getString(i));
40-
}
41-
});
42-
}
43-
return collected;
44-
}
45-
4629
@Test
4730
void lowCardinality_utf8_acrossChunks_usesGlobalDict(@TempDir Path tmp) throws IOException {
4831
// Given — 3 distinct values repeated across multiple chunks; cycling produces
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package io.github.dfa1.vortex.writer;
2+
3+
import io.github.dfa1.vortex.core.array.Array;
4+
import io.github.dfa1.vortex.core.array.ArraySegments;
5+
import io.github.dfa1.vortex.core.array.VarBinArray;
6+
import io.github.dfa1.vortex.reader.ScanOptions;
7+
import io.github.dfa1.vortex.reader.VortexReader;
8+
9+
import java.lang.foreign.ValueLayout;
10+
import java.nio.ByteOrder;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
/// Shared scan-and-collect helpers for writer round-trip tests. Materialise each
15+
/// chunk's values into a heap container before the chunk's arena closes; the
16+
/// returned arrays/lists outlive the scan lifecycle.
17+
final class VortexReads {
18+
19+
private static final ValueLayout.OfInt LE_INT =
20+
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
21+
private static final ValueLayout.OfLong LE_LONG =
22+
ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
23+
24+
private VortexReads() {
25+
}
26+
27+
static int[] readAllInts(VortexReader vf, String col) {
28+
var collected = new ArrayList<Integer>();
29+
try (var iter = vf.scan(ScanOptions.all())) {
30+
iter.forEachRemaining(c -> {
31+
Array arr = c.column(col);
32+
for (long i = 0; i < arr.length(); i++) {
33+
collected.add(ArraySegments.of(arr).get(LE_INT, i * Integer.BYTES));
34+
}
35+
});
36+
}
37+
return collected.stream().mapToInt(Integer::intValue).toArray();
38+
}
39+
40+
static long[] readAllLongs(VortexReader vf, String col) {
41+
var collected = new ArrayList<Long>();
42+
try (var iter = vf.scan(ScanOptions.all())) {
43+
iter.forEachRemaining(c -> {
44+
Array arr = c.column(col);
45+
for (long i = 0; i < arr.length(); i++) {
46+
collected.add(ArraySegments.of(arr).get(LE_LONG, i * Long.BYTES));
47+
}
48+
});
49+
}
50+
return collected.stream().mapToLong(Long::longValue).toArray();
51+
}
52+
53+
static List<String> readAllStrings(VortexReader vf, String col) {
54+
var collected = new ArrayList<String>();
55+
try (var iter = vf.scan(ScanOptions.all())) {
56+
iter.forEachRemaining(c -> {
57+
VarBinArray vb = (VarBinArray) c.column(col);
58+
for (long i = 0; i < vb.length(); i++) {
59+
collected.add(vb.getString(i));
60+
}
61+
});
62+
}
63+
return collected;
64+
}
65+
}

0 commit comments

Comments
 (0)