Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private void writeColumnBatch(VectorizedBundleRecords vectors) {
private int prepareVectorizedBatch(
ColumnVector[] columns, @Nullable int[] selected, int startIndex, int maxBatchRows) {
// Consume successful slices once and carry their measured size into the next slice.
// Double at most: a short prefix must not trigger allocation for an entire skewed batch.
// Grow conservatively: a short prefix must not allocate an entire skewed batch.
int batchRows = Math.min(vectorBatchRows, maxBatchRows);
while (true) {
long memoryUsed;
Expand All @@ -353,13 +353,18 @@ private int prepareVectorizedBatch(
continue;
}

int nextBatchRows =
batchRows > Integer.MAX_VALUE / 2 ? Integer.MAX_VALUE : batchRows * 2;
if (maxBatchRows < vectorBatchRows && batchRows == maxBatchRows) {
// An input-limited tail does not invalidate the previous target. Memory usage
// can still lower it below, and allocation or memory retries bypass this case.
nextBatchRows = Math.max(nextBatchRows, vectorBatchRows);
}
vectorBatchRows =
Math.min(
arrowFormatWriter.getBatchSize(),
Math.min(
batchRows > Integer.MAX_VALUE / 2
? Integer.MAX_VALUE
: batchRows * 2,
nextBatchRows,
rowsWithinMemory(batchRows, memoryUsed, writeBatchMemory)));
return batchRows;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,34 @@ void testMapFallbackPreservesLogicalOffsets(boolean selected) throws Exception {
}
}

@Test
void testShortBundlesPreserveBatchSize() throws Exception {
RowType rowType = RowType.builder().field("a", DataTypes.STRING()).build();
List<Integer> batchRowCounts = new ArrayList<>();
List<String> writtenValues = new ArrayList<>();
MosaicWriter nativeWriter =
capturingWriter(
root -> {
batchRowCounts.add(root.getRowCount());
VarCharVector column = (VarCharVector) root.getVector(0);
for (int i = 0; i < root.getRowCount(); i++) {
writtenValues.add(column.getObject(i).toString());
}
});
HeapBytesVector values = new HeapBytesVector(150);
for (int i = 0; i < 150; i++) {
values.putByteArray(i, new byte[] {'a'}, 0, 1);
}
try (MosaicRecordsWriter writer = createWriter(rowType, nativeWriter)) {
for (int rows : new int[] {150, 150, 150, 1, 150}) {
writer.writeBundle(new VectorizedBundleRecords(batch(rows, values), null));
}
}

assertThat(batchRowCounts).containsExactly(32, 64, 54, 128, 22, 150, 1, 150);
assertThat(writtenValues).containsExactlyElementsOf(Collections.nCopies(601, "a"));
}

@Test
void testVectorizedBundleRespectsWriteBatchMemory() throws Exception {
RowType rowType = RowType.builder().field("a", DataTypes.STRING()).build();
Expand Down
Loading