Skip to content

Commit cfeb551

Browse files
dfa1claude
andcommitted
test(reader): cover overflowed-zone null path in ZoneReducer
Add an overflowed-zone case to ZoneReducerTest: zone maps enabled but one I64 chunk's SUM overflows (Math.addExact drops it), so the zone-map table is present yet a zone carries no usable sum — exercising the fold's bail path distinctly from the absent-table case. Also add WriteOptions.withZoneMaps(boolean), mirroring withGlobalDict / withZstd, so the no-zone-map test reads as WriteOptions.defaults().withZoneMaps(false) instead of a brittle positional constructor call. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 70191f1 commit cfeb551

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

writer/src/main/java/io/github/dfa1/vortex/writer/WriteOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public static WriteOptions cascading(int depth) {
3737
return new WriteOptions(65_536, true, 0.90, depth, true, false);
3838
}
3939

40+
/// Returns a copy of these options with zone-map statistics set to `enabled`.
41+
///
42+
/// @param enabled `true` to write per-chunk min/max/sum statistics for zone-map pruning
43+
/// @return a new `WriteOptions` with the zone-map flag updated
44+
public WriteOptions withZoneMaps(boolean enabled) {
45+
return new WriteOptions(chunkSize, enabled, compressionRatioThreshold, allowedCascading, globalDict, enableZstd);
46+
}
47+
4048
/// Returns a copy of these options with global dictionary encoding set to `enabled`.
4149
///
4250
/// @param enabled `true` to enable global dictionary encoding across chunks

writer/src/test/java/io/github/dfa1/vortex/writer/ZoneReducerTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void floatSumFoldsZonesToDouble(@TempDir Path tmp) throws IOException {
8181
void noZoneMapYieldsNull(@TempDir Path tmp) throws IOException {
8282
// Given — zone maps disabled, so no per-zone SUM exists to fold
8383
Path file = tmp.resolve("nostats.vtx");
84-
WriteOptions noZoneMaps = new WriteOptions(65_536, false, 0.90, 0, true, false);
84+
WriteOptions noZoneMaps = WriteOptions.defaults().withZoneMaps(false);
8585
try (var ch = FileChannel.open(file, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
8686
var w = VortexWriter.create(ch, I64_SCHEMA, noZoneMaps)) {
8787
w.writeChunk(Map.of("id", range(1L, 50L)));
@@ -95,4 +95,25 @@ void noZoneMapYieldsNull(@TempDir Path tmp) throws IOException {
9595
assertThat(result).isNull();
9696
}
9797
}
98+
99+
@Test
100+
void overflowedZoneYieldsNull(@TempDir Path tmp) throws IOException {
101+
// Given — zone maps ON, but one zone's I64 SUM overflows long (Math.addExact in the writer
102+
// drops it), so a zone map exists yet a zone carries no usable sum. Distinct from
103+
// noZoneMapYieldsNull: there the table is absent; here it is present but incomplete.
104+
Path file = tmp.resolve("overflow.vtx");
105+
try (var ch = FileChannel.open(file, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
106+
var w = VortexWriter.create(ch, I64_SCHEMA, WriteOptions.defaults())) {
107+
w.writeChunk(Map.of("id", range(1L, 50L))); // sums fine
108+
w.writeChunk(Map.of("id", new long[]{Long.MAX_VALUE, Long.MAX_VALUE})); // overflows
109+
}
110+
111+
// When
112+
try (VortexReader reader = VortexReader.open(file, registry())) {
113+
Number result = new ZoneReducer(reader).sum("id");
114+
115+
// Then — one unusable zone forces the whole fold to bail; no partial sum returned
116+
assertThat(result).isNull();
117+
}
118+
}
98119
}

0 commit comments

Comments
 (0)