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 a15969315c [common] Fix row-id pruning for maximum range bounds 
(#11105)
a15969315c is described below

commit a15969315c5965656d5fb33a396639ef99f169af
Author: YueZhang <[email protected]>
AuthorDate: Thu Nov 12 13:12:15 2026 +0800

    [common] Fix row-id pruning for maximum range bounds (#11105)
---
 .../main/java/org/apache/paimon/utils/Range.java   |  4 +--
 .../predicate/RowIdPredicateVisitorTest.java       | 10 ++++++++
 .../org/apache/paimon/utils/RowRangeIndexTest.java | 10 ++++++++
 .../paimon/table/DataEvolutionTableTest.java       | 29 ++++++++++++++++++++++
 4 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/Range.java 
b/paimon-common/src/main/java/org/apache/paimon/utils/Range.java
index cdebaa342c..814234b742 100644
--- a/paimon-common/src/main/java/org/apache/paimon/utils/Range.java
+++ b/paimon-common/src/main/java/org/apache/paimon/utils/Range.java
@@ -138,8 +138,8 @@ public class Range implements Serializable {
 
         for (int i = 1; i < sorted.size(); i++) {
             Range next = sorted.get(i);
-            // Check if current and next overlap (not just adjacent)
-            if (current.to + (adjacent ? 1 : 0) >= next.from) {
+            // Check overlap first, since adding one to Long.MAX_VALUE would 
overflow.
+            if (current.to >= next.from || (adjacent && current.to + 1 == 
next.from)) {
                 // Merge: extend current range
                 current = new Range(current.from, Math.max(current.to, 
next.to));
             } else {
diff --git 
a/paimon-common/src/test/java/org/apache/paimon/predicate/RowIdPredicateVisitorTest.java
 
b/paimon-common/src/test/java/org/apache/paimon/predicate/RowIdPredicateVisitorTest.java
index abaa07894f..dd055c6976 100644
--- 
a/paimon-common/src/test/java/org/apache/paimon/predicate/RowIdPredicateVisitorTest.java
+++ 
b/paimon-common/src/test/java/org/apache/paimon/predicate/RowIdPredicateVisitorTest.java
@@ -190,6 +190,16 @@ public class RowIdPredicateVisitorTest {
         assertThat(orResult.get()).containsExactly(new Range(7, 7));
     }
 
+    @Test
+    public void testOrWithMaximumRowIdBound() {
+        Predicate predicate =
+                PredicateBuilder.or(
+                        builder.between(rowIdIndex, 0L, Long.MAX_VALUE),
+                        builder.equal(rowIdIndex, 0L));
+        assertThat(predicate.visit(visitor))
+                .contains(Collections.singletonList(new Range(0, 
Long.MAX_VALUE)));
+    }
+
     @Test
     public void testCompoundedPredicate() {
         // Test AND intersection
diff --git 
a/paimon-common/src/test/java/org/apache/paimon/utils/RowRangeIndexTest.java 
b/paimon-common/src/test/java/org/apache/paimon/utils/RowRangeIndexTest.java
index 8a6dc99c59..f1d0b2d073 100644
--- a/paimon-common/src/test/java/org/apache/paimon/utils/RowRangeIndexTest.java
+++ b/paimon-common/src/test/java/org/apache/paimon/utils/RowRangeIndexTest.java
@@ -48,6 +48,16 @@ class RowRangeIndexTest {
                         new Range(Long.MAX_VALUE, Long.MAX_VALUE));
     }
 
+    @Test
+    void testOverlappingRangeWithMaximumEnd() {
+        RowRangeIndex index =
+                RowRangeIndex.create(Arrays.asList(new Range(0, 
Long.MAX_VALUE), new Range(0, 0)));
+
+        assertThat(index.intersects(1, 9)).isTrue();
+        assertThat(index.contains(new Range(1, 9))).isTrue();
+        assertThat(index.intersectedRanges(1, 9)).containsExactly(new Range(1, 
9));
+    }
+
     @Test
     void testContains() {
         RowRangeIndex index =
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionTableTest.java 
b/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionTableTest.java
index a6ee4254eb..1a5347278b 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionTableTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/table/DataEvolutionTableTest.java
@@ -605,6 +605,35 @@ public class DataEvolutionTableTest extends 
DataEvolutionTestBase {
         assertThat(plannedFirstRowIds(plan)).isEqualTo(Arrays.asList(0L, 1L));
     }
 
+    @Test
+    public void testRowIdOrWithMaximumBoundReadsAllRows() throws Exception {
+        createTableDefault();
+        Schema schema = schemaDefault();
+        BatchWriteBuilder writeBuilder = 
getTableDefault().newBatchWriteBuilder();
+        for (int batch = 0; batch < 2; batch++) {
+            try (BatchTableWrite write = writeBuilder.newWrite();
+                    BatchTableCommit commit = writeBuilder.newCommit()) {
+                for (int i = batch * 5; i < (batch + 1) * 5; i++) {
+                    write.write(
+                            GenericRow.of(
+                                    i,
+                                    BinaryString.fromString("a" + i),
+                                    BinaryString.fromString("b" + i)));
+                }
+                commit.commit(write.prepareCommit());
+            }
+        }
+
+        PredicateBuilder builder = new 
PredicateBuilder(rowTypeWithRowId(schema));
+        int rowIdIndex = schema.rowType().getFieldCount();
+        Predicate filter =
+                PredicateBuilder.or(
+                        builder.between(rowIdIndex, 0L, Long.MAX_VALUE),
+                        builder.equal(rowIdIndex, 0L));
+
+        assertThat(readF0WithFilter(filter)).isEqualTo(Arrays.asList(0, 1, 2, 
3, 4, 5, 6, 7, 8, 9));
+    }
+
     @Test
     public void testDescendingRowIdInIntersectBetweenReadsCorrectRows() throws 
Exception {
         // Table-level regression: a descending _ROW_ID IN list intersected 
with a BETWEEN used to

Reply via email to