Skip to content

Commit 1dde052

Browse files
committed
refactor: drop empty-batch workaround in MetadataResultSets
Now that ArrowStreamReaderCursor.loadNextNonEmptyBatch (introduced earlier on this branch as a pre-unify cursor fix) consumes empty batches at the cursor seam, MetadataResultSets.writeArrowStream no longer needs its own "skip writeBatch when rowCount==0" workaround: the cursor handles the empty-only case correctly. Remove the special case and always emit a batch. Tightens the zeroRowOnlyBatchYieldsNoRows test docstring to match.
1 parent 9f0b7c4 commit 1dde052

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

jdbc-core/src/main/java/com/salesforce/datacloud/jdbc/core/metadata/MetadataResultSets.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ private static byte[] writeArrowStream(List<ColumnMetadata> columns, List<List<O
9696
ByteArrayOutputStream out = new ByteArrayOutputStream();
9797
try (ArrowStreamWriter writer = new ArrowStreamWriter(root, null, out)) {
9898
writer.start();
99-
// Skip writeBatch() for empty results — writing a zero-row batch confuses the
100-
// cursor (see ArrowStreamReaderCursor.next), which interprets a successfully
101-
// loaded batch as "at least one row available".
102-
if (root.getRowCount() > 0) {
103-
writer.writeBatch();
104-
}
99+
writer.writeBatch();
105100
writer.end();
106101
}
107102
return out.toByteArray();

jdbc-core/src/test/java/com/salesforce/datacloud/jdbc/core/ArrowStreamReaderCursorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ void incrementsInternalIndexUntilRowsExhaustedThenLoadsNextBatch() {
6464
val sut = new ArrowStreamReaderCursor(reader, allocator, ZoneId.systemDefault());
6565
IntStream.range(0, times + 1).forEach(i -> sut.next());
6666

67+
// Each next() inspects rowCount once on the per-batch index check. loadNextNonEmptyBatch
68+
// is reached on the (times+1)-th call but only inspects rowCount inside its loop body if
69+
// loadNextBatch returns true; here it returns false, so getRowCount is observed times+1
70+
// times in total.
6771
verify(root, times(times + 1)).getRowCount();
6872
verify(reader, times(1)).loadNextBatch();
6973
}

0 commit comments

Comments
 (0)