Skip to content

Commit 149b382

Browse files
committed
Preserve split plan continuations and locality validation
1 parent 7ceafb1 commit 149b382

4 files changed

Lines changed: 30 additions & 10 deletions

File tree

‎vgi/src/main/java/farm/query/vgi/internal/ScanSplitSerializer.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ public static byte[] serialize(ScanSplit split) {
8888
if (split.location_ids() == null) {
8989
locations.setNull(0);
9090
} else {
91+
if (split.location_ids().stream().anyMatch(java.util.Objects::isNull)) {
92+
throw new IllegalArgumentException("ScanSplit.location_ids must not contain null elements");
93+
}
9194
UnionListWriter w = locations.getWriter();
9295
w.setPosition(0);
9396
w.startList();
9497
for (Long id : split.location_ids()) {
95-
w.bigInt().writeBigInt(id == null ? 0L : id);
98+
w.bigInt().writeBigInt(id);
9699
}
97100
w.endList();
98101
}

‎vgi/src/main/java/farm/query/vgi/internal/VgiServiceImpl.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,12 +1115,8 @@ public PlanResponse table_function_plan(byte[] request, CallContext ctx) {
11151115
// only the first wants a default.
11161116
splitCapable = fn.metadata().supportsSplits();
11171117
}
1118-
if (planned.isEmpty()) {
1119-
return splitCapable
1120-
? new PlanResponse(List.of(), List.of(), null, new byte[0], null, 0L, 0L,
1121-
null, null, "catalog", null, List.of(), List.of(), null,
1122-
new byte[0], new byte[0])
1123-
: PlanResponse.of(List.of(defaultSplitBytes()));
1118+
if (planned.isEmpty() && !splitCapable) {
1119+
return PlanResponse.of(List.of(defaultSplitBytes()));
11241120
}
11251121

11261122
byte[] fingerprint = SplitToken.bindFingerprint(

‎vgi/src/test/java/farm/query/vgi/client/PlanClientRoundTripTest.java‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,19 @@ static final class PlanSeqFunction implements TableFunction {
140140
long splits = namedLong(params, "splits");
141141
List<Range> all = evenRanges(n, splits);
142142

143+
// A split-capable worker may need a continuation before it can
144+
// produce its first split. The service must preserve this empty
145+
// page instead of replacing it with a terminal whole-scan answer.
146+
if (request.cursor() == null || request.cursor().length == 0) {
147+
return new PlanResult(
148+
List.of(),
149+
List.of(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(0).array()),
150+
null, (long) all.size(), n, 2L);
151+
}
152+
143153
long cap = request.maxSplitsPerResponse() == null
144154
? all.size() : request.maxSplitsPerResponse();
145-
long page = request.cursor() == null || request.cursor().length == 0
146-
? 0 : ByteBuffer.wrap(request.cursor()).order(ByteOrder.LITTLE_ENDIAN).getLong();
155+
long page = ByteBuffer.wrap(request.cursor()).order(ByteOrder.LITTLE_ENDIAN).getLong();
147156
int lo = (int) Math.min(page * cap, all.size());
148157
int hi = (int) Math.min(lo + cap, all.size());
149158

@@ -248,7 +257,7 @@ void plansAndRedeemsEverySplitAcrossPagination() throws Exception {
248257
assertTrue(pages < 10, "runaway pagination — next_cursors never emptied");
249258
planReq = planReq.withCursor(resp.next_cursors().get(0), 2);
250259
}
251-
assertEquals(3, pages, "6 splits at 2 per page must take exactly 3 calls");
260+
assertEquals(4, pages, "one empty continuation page plus 3 split pages");
252261
assertEquals(6, tokens.size(), "all 6 splits across every page");
253262

254263
// REDEEM every split and drain it, collecting the union of rows.

‎vgi/src/test/java/farm/query/vgi/internal/SplitRedemptionTest.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ void aStampedSplitCarriesItsTokenOnTheWire() {
9292
org.junit.jupiter.api.Assertions.assertTrue(wire.length > 0);
9393
}
9494

95+
@Test
96+
void nullableLocationIdsAreRejectedInsteadOfSilentlyBecomingZero() {
97+
farm.query.vgi.protocol.ScanSplit split = new farm.query.vgi.protocol.ScanSplit(
98+
new byte[0], new byte[] {1}, null, false, null,
99+
null, null, null, null, null, java.util.Arrays.asList(1L, null), null, null);
100+
101+
IllegalArgumentException error = assertThrows(
102+
IllegalArgumentException.class, () -> ScanSplitSerializer.serialize(split));
103+
104+
org.junit.jupiter.api.Assertions.assertTrue(error.getMessage().contains("location_ids"));
105+
}
106+
95107
/** Tiny holder so the assertions above read as intent rather than accessors. */
96108
private record ScanSplitLike(farm.query.vgi.protocol.ScanSplit split) {
97109
byte[] token() {

0 commit comments

Comments
 (0)