This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 2808e298a3 [core] Skip empty merged-read batches iteratively (#11137)
2808e298a3 is described below
commit 2808e298a321c8b0f8c95e9a16b98d1d72895e61
Author: YueZhang <[email protected]>
AuthorDate: Fri Nov 13 18:51:41 2026 +0800
[core] Skip empty merged-read batches iteratively (#11137)
---
.../paimon/append/ForceSingleBatchReader.java | 18 ++--
.../paimon/append/ForceSingleBatchReaderTest.java | 100 +++++++++++++++++++++
.../table/DataEvolutionDeletionVectorTest.java | 24 +++++
3 files changed, 133 insertions(+), 9 deletions(-)
diff --git
a/paimon-core/src/main/java/org/apache/paimon/append/ForceSingleBatchReader.java
b/paimon-core/src/main/java/org/apache/paimon/append/ForceSingleBatchReader.java
index c3db10001c..fe85d61a39 100644
---
a/paimon-core/src/main/java/org/apache/paimon/append/ForceSingleBatchReader.java
+++
b/paimon-core/src/main/java/org/apache/paimon/append/ForceSingleBatchReader.java
@@ -81,22 +81,22 @@ public class ForceSingleBatchReader implements
RecordReader<InternalRow> {
@Nullable
@Override
public InternalRow next() throws IOException {
- if (currentBatch == null) {
- currentBatch = reader.readBatch();
+ while (true) {
if (currentBatch == null) {
- return null;
+ currentBatch = reader.readBatch();
+ if (currentBatch == null) {
+ return null;
+ }
}
- }
- InternalRow next = currentBatch.next();
+ InternalRow next = currentBatch.next();
+ if (next != null) {
+ return next;
+ }
- if (next == null) {
currentBatch.releaseBatch();
currentBatch = null;
- return next();
}
-
- return next;
}
@Override
diff --git
a/paimon-core/src/test/java/org/apache/paimon/append/ForceSingleBatchReaderTest.java
b/paimon-core/src/test/java/org/apache/paimon/append/ForceSingleBatchReaderTest.java
new file mode 100644
index 0000000000..25a1a6496e
--- /dev/null
+++
b/paimon-core/src/test/java/org/apache/paimon/append/ForceSingleBatchReaderTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.append;
+
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.reader.RecordReader;
+
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link ForceSingleBatchReader}. */
+class ForceSingleBatchReaderTest {
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void testConsecutiveEmptyBatches(boolean withRecords) throws Exception {
+ int batchCount = 60002;
+ AtomicInteger released = new AtomicInteger();
+ AtomicBoolean closed = new AtomicBoolean();
+ RecordReader<InternalRow> input =
+ new RecordReader<InternalRow>() {
+ private int nextBatch;
+
+ @Override
+ public RecordIterator<InternalRow> readBatch() {
+ assertThat(released.get()).isEqualTo(nextBatch);
+ if (nextBatch == batchCount) {
+ return null;
+ }
+ int batchIndex = nextBatch++;
+ return new RecordIterator<InternalRow>() {
+ private boolean returned;
+
+ @Override
+ public InternalRow next() {
+ if (!returned
+ && withRecords
+ && (batchIndex == 20000 || batchIndex
== 40001)) {
+ returned = true;
+ return GenericRow.of(batchIndex);
+ }
+ return null;
+ }
+
+ @Override
+ public void releaseBatch() {
+ released.incrementAndGet();
+ }
+ };
+ }
+
+ @Override
+ public void close() {
+ closed.set(true);
+ }
+ };
+
+ List<Integer> values = new ArrayList<>();
+ try (ForceSingleBatchReader reader = new
ForceSingleBatchReader(input)) {
+ RecordReader.RecordIterator<InternalRow> batch =
reader.readBatch();
+ InternalRow row;
+ while ((row = batch.next()) != null) {
+ values.add(row.getInt(0));
+ }
+ batch.releaseBatch();
+ assertThat(reader.readBatch()).isNull();
+ }
+ if (withRecords) {
+ assertThat(values).containsExactly(20000, 40001);
+ } else {
+ assertThat(values).isEmpty();
+ }
+ assertThat(released.get()).isEqualTo(batchCount);
+ assertThat(closed.get()).isTrue();
+ }
+}
diff --git
a/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionDeletionVectorTest.java
b/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionDeletionVectorTest.java
index a0c2afa26c..2ae854da31 100644
---
a/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionDeletionVectorTest.java
+++
b/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionDeletionVectorTest.java
@@ -110,6 +110,30 @@ public class DataEvolutionDeletionVectorTest extends
DataEvolutionTestBase {
new DvSpec(new Range(5, 9), 6),
new DvSpec(new Range(10, 14), 10, 12));
+ @Test
+ public void testMergedReadAfterManyDeletedBatches() throws Exception {
+ int rowCount = 20000;
+ write(rowCount);
+ FileStoreTable table = getTableDefault();
+ long[] deleted = new long[rowCount - 1];
+ for (int i = 0; i < deleted.length; i++) {
+ deleted[i] = i;
+ }
+ commitDeletionVectors(
+ table, Collections.singletonList(new DvSpec(new Range(0,
rowCount - 1), deleted)));
+
+ table =
+ getTableDefault()
+
.copy(Collections.singletonMap(CoreOptions.READ_BATCH_SIZE.key(), "1"));
+ ReadBuilder readBuilder = table.newReadBuilder().withProjection(new
int[] {0, 2});
+ List<String> rows = new ArrayList<>();
+ try (RecordReader<InternalRow> reader =
+
readBuilder.newRead().createReader(readBuilder.newScan().plan())) {
+ reader.forEachRemaining(row -> rows.add(row.getInt(0) + "|" +
row.getString(1)));
+ }
+ assertThat(rows).containsExactly("19999|b19999");
+ }
+
@Test
public void testReadAfterDeletionVectors() throws Exception {
// basic read