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 6b60afaf25 [common] Bound bitmap dictionary scans for range predicates 
(#11131)
6b60afaf25 is described below

commit 6b60afaf25405e5a2c989d3e696cf802957cc0a9
Author: YueZhang <[email protected]>
AuthorDate: Fri Nov 13 18:52:58 2026 +0800

    [common] Bound bitmap dictionary scans for range predicates (#11131)
---
 .../globalindex/bitmap/BitmapIndexReader.java      | 29 ++++++---
 .../bitmap/LazyFilteredBitmapIndexReaderTest.java  | 68 ++++++++++++++++++++--
 2 files changed, 86 insertions(+), 11 deletions(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/globalindex/bitmap/BitmapIndexReader.java
 
b/paimon-common/src/main/java/org/apache/paimon/globalindex/bitmap/BitmapIndexReader.java
index 2828f28852..7661714c5e 100644
--- 
a/paimon-common/src/main/java/org/apache/paimon/globalindex/bitmap/BitmapIndexReader.java
+++ 
b/paimon-common/src/main/java/org/apache/paimon/globalindex/bitmap/BitmapIndexReader.java
@@ -28,6 +28,8 @@ import org.apache.paimon.utils.IOUtils;
 import org.apache.paimon.utils.LazyField;
 import org.apache.paimon.utils.RoaringNavigableMap64;
 
+import javax.annotation.Nullable;
+
 import java.io.Closeable;
 import java.io.IOException;
 import java.util.Comparator;
@@ -148,14 +150,14 @@ class BitmapIndexReader implements 
BitmapGlobalIndexFormat.SeekableReader, Close
         if (literal == null) {
             return new RoaringNavigableMap64();
         }
-        return scanDictionary(key -> comparator.compare(key, literal) < 0);
+        return scanDictionary(key -> comparator.compare(key, literal) < 0, 
null, literal);
     }
 
     RoaringNavigableMap64 greaterThan(Object literal) {
         if (literal == null) {
             return new RoaringNavigableMap64();
         }
-        return scanDictionary(key -> comparator.compare(key, literal) > 0);
+        return scanDictionary(key -> comparator.compare(key, literal) > 0, 
literal, null);
     }
 
     @Override
@@ -273,14 +275,14 @@ class BitmapIndexReader implements 
BitmapGlobalIndexFormat.SeekableReader, Close
         if (literal == null) {
             return new RoaringNavigableMap64();
         }
-        return scanDictionary(key -> comparator.compare(key, literal) >= 0);
+        return scanDictionary(key -> comparator.compare(key, literal) >= 0, 
literal, null);
     }
 
     private RoaringNavigableMap64 lessOrEqual(Object literal) {
         if (literal == null) {
             return new RoaringNavigableMap64();
         }
-        return scanDictionary(key -> comparator.compare(key, literal) <= 0);
+        return scanDictionary(key -> comparator.compare(key, literal) <= 0, 
null, literal);
     }
 
     private RoaringNavigableMap64 between(Object from, Object to) {
@@ -288,7 +290,9 @@ class BitmapIndexReader implements 
BitmapGlobalIndexFormat.SeekableReader, Close
             return new RoaringNavigableMap64();
         }
         return scanDictionary(
-                key -> comparator.compare(key, from) >= 0 && 
comparator.compare(key, to) <= 0);
+                key -> comparator.compare(key, from) >= 0 && 
comparator.compare(key, to) <= 0,
+                from,
+                to);
     }
 
     private RoaringNavigableMap64 notEqual(Object literal) {
@@ -314,9 +318,20 @@ class BitmapIndexReader implements 
BitmapGlobalIndexFormat.SeekableReader, Close
     }
 
     private RoaringNavigableMap64 scanDictionary(Predicate<Object> 
keyPredicate) {
+        return scanDictionary(keyPredicate, null, null);
+    }
+
+    private RoaringNavigableMap64 scanDictionary(
+            Predicate<Object> keyPredicate, @Nullable Object lower, @Nullable 
Object upper) {
         RoaringNavigableMap64 result = new RoaringNavigableMap64();
-        for (BitmapGlobalIndexFormat.DictionaryBlockMeta blockMeta : 
dictionaryBlocks.get()) {
-            BitmapGlobalIndexFormat.DictionaryBlock dictionaryBlock = 
dictionaryBlock(blockMeta);
+        List<BitmapGlobalIndexFormat.DictionaryBlockMeta> blocks = 
dictionaryBlocks.get();
+        int firstBlock =
+                lower == null ? 0 : Math.max(0, 
findLogicalDictionaryBlockIndex(blocks, lower));
+        int endBlock =
+                upper == null ? blocks.size() : 
findLogicalDictionaryBlockIndex(blocks, upper) + 1;
+        for (int i = firstBlock; i < endBlock; i++) {
+            BitmapGlobalIndexFormat.DictionaryBlock dictionaryBlock =
+                    dictionaryBlock(blocks.get(i));
             for (BitmapGlobalIndexFormat.DictionaryEntry entry : 
dictionaryBlock.entries) {
                 Object key = 
keySerializer.deserialize(MemorySlice.wrap(entry.key.bytes()));
                 if (keyPredicate.test(key)) {
diff --git 
a/paimon-common/src/test/java/org/apache/paimon/globalindex/bitmap/LazyFilteredBitmapIndexReaderTest.java
 
b/paimon-common/src/test/java/org/apache/paimon/globalindex/bitmap/LazyFilteredBitmapIndexReaderTest.java
index 64864733f2..389e1a7d72 100644
--- 
a/paimon-common/src/test/java/org/apache/paimon/globalindex/bitmap/LazyFilteredBitmapIndexReaderTest.java
+++ 
b/paimon-common/src/test/java/org/apache/paimon/globalindex/bitmap/LazyFilteredBitmapIndexReaderTest.java
@@ -42,6 +42,8 @@ import org.apache.paimon.utils.Pair;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -255,8 +257,11 @@ public class LazyFilteredBitmapIndexReaderTest {
                 org.apache.paimon.options.MemorySize.ofBytes(1));
         BitmapGlobalIndexer intIndexer = new BitmapGlobalIndexer(intField, 
options);
         GlobalIndexSingleColumnWriter writer = 
intIndexer.createWriter(fileWriter);
-        writer.write(-1, 0);
-        writer.write(0, 1);
+        int[] keys = {-1000, -256, -1, 0, 1, 255, 256, 1000};
+        for (int i = 0; i < keys.length; i++) {
+            writer.write(keys[i], i);
+        }
+        writer.write(null, keys.length);
         ResultEntry result = writer.finish().get(0);
         Path filePath = new Path(basePath, result.fileName());
         GlobalIndexIOMeta meta =
@@ -266,10 +271,65 @@ public class LazyFilteredBitmapIndexReaderTest {
                 intIndexer.createReader(
                         fileReader,
                         Collections.singletonList(meta),
-                        2,
+                        keys.length + 1,
+                        null,
+                        newDirectExecutorService())) {
+            assertRows(reader.visitEqual(intFieldRef, 0).join(), 3L);
+            assertRows(reader.visitLessThan(intFieldRef, -256).join(), 0L);
+            assertRows(reader.visitLessOrEqual(intFieldRef, -256).join(), 0L, 
1L);
+            assertRows(reader.visitGreaterThan(intFieldRef, 255).join(), 6L, 
7L);
+            assertRows(reader.visitGreaterOrEqual(intFieldRef, 255).join(), 
5L, 6L, 7L);
+            assertRows(reader.visitBetween(intFieldRef, -256, 255).join(), 1L, 
2L, 3L, 4L, 5L);
+            assertRows(reader.visitBetween(intFieldRef, -255, 254).join(), 2L, 
3L, 4L);
+            assertRows(
+                    reader.visitBetween(intFieldRef, -2000, 2000).join(),
+                    0L,
+                    1L,
+                    2L,
+                    3L,
+                    4L,
+                    5L,
+                    6L,
+                    7L);
+            assertRows(reader.visitBetween(intFieldRef, 2, 254).join());
+            assertRows(reader.visitBetween(intFieldRef, 1001, 2000).join());
+            assertRows(reader.visitBetween(intFieldRef, -2000, -1001).join());
+            assertRows(reader.visitBetween(intFieldRef, 1, -1).join());
+        }
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {"none", "lz4", "zstd", "lzo"})
+    public void testRangeLookupSkipsUnrelatedDictionaryBlocks(String 
compression) throws Exception {
+        Options options = new Options();
+        options.set(BitmapGlobalIndexOptions.BITMAP_INDEX_COMPRESSION, 
compression);
+        options.set(
+                BitmapGlobalIndexOptions.BITMAP_INDEX_DICTIONARY_BLOCK_SIZE,
+                org.apache.paimon.options.MemorySize.ofBytes(256));
+        globalIndexer = new BitmapGlobalIndexer(dataField, options);
+        List<Pair<BinaryString, Long>> rows = new ArrayList<>();
+        for (int i = 0; i < 2000; i++) {
+            rows.add(Pair.of(str(String.format("key-%04d", i)), (long) i));
+        }
+        GlobalIndexIOMeta meta = writeData(rows);
+        CountingGlobalIndexFileReader countingReader = new 
CountingGlobalIndexFileReader();
+        try (GlobalIndexReader reader =
+                globalIndexer.createReader(
+                        countingReader,
+                        Collections.singletonList(meta),
+                        rows.size(),
                         null,
                         newDirectExecutorService())) {
-            assertRows(reader.visitEqual(intFieldRef, 0).join(), 1L);
+            assertRows(
+                    reader.visitBetween(fieldRef, str("key-0998"), 
str("key-1002")).join(),
+                    998L,
+                    999L,
+                    1000L,
+                    1001L,
+                    1002L);
+            assertThat(countingReader.seekCount())
+                    .as("footer, index, boundary dictionary blocks and 
matching bitmaps")
+                    .isLessThanOrEqualTo(12);
         }
     }
 

Reply via email to