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 a9aaba86f1 [common] Always accept the first entry in bitmap index 
block packing (#9614)
a9aaba86f1 is described below

commit a9aaba86f1c16ee478da8be2506089e86c4a4075
Author: YangJie <[email protected]>
AuthorDate: Thu Sep 10 02:33:59 2026 -0400

    [common] Always accept the first entry in bitmap index block packing (#9614)
---
 .../fileindex/bitmap/BitmapFileIndexMetaV2.java    |  5 ++-
 .../fileindex/bitmapindex/BitmapFileIndexTest.java | 36 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/fileindex/bitmap/BitmapFileIndexMetaV2.java
 
b/paimon-common/src/main/java/org/apache/paimon/fileindex/bitmap/BitmapFileIndexMetaV2.java
index f92e008162..8e6d79a0a1 100644
--- 
a/paimon-common/src/main/java/org/apache/paimon/fileindex/bitmap/BitmapFileIndexMetaV2.java
+++ 
b/paimon-common/src/main/java/org/apache/paimon/fileindex/bitmap/BitmapFileIndexMetaV2.java
@@ -377,7 +377,10 @@ public class BitmapFileIndexMetaV2 extends 
BitmapFileIndexMeta {
                 key = entry.key;
             }
             int entryBytes = 2 * Integer.BYTES + 
keyBytesMapper.apply(entry.key);
-            if (serializedBytes + entryBytes > blockSizeLimit) {
+            // an empty block always accepts its first entry: the block size 
limit is a
+            // packing target, and rejecting a single oversized key would fail 
the whole
+            // index serialization
+            if (!entryList.isEmpty() && serializedBytes + entryBytes > 
blockSizeLimit) {
                 return false;
             }
             serializedBytes += entryBytes;
diff --git 
a/paimon-common/src/test/java/org/apache/paimon/fileindex/bitmapindex/BitmapFileIndexTest.java
 
b/paimon-common/src/test/java/org/apache/paimon/fileindex/bitmapindex/BitmapFileIndexTest.java
index cf67e9c2fe..1c56662ab1 100644
--- 
a/paimon-common/src/test/java/org/apache/paimon/fileindex/bitmapindex/BitmapFileIndexTest.java
+++ 
b/paimon-common/src/test/java/org/apache/paimon/fileindex/bitmapindex/BitmapFileIndexTest.java
@@ -34,6 +34,7 @@ import org.apache.paimon.types.DataTypes;
 import org.apache.paimon.types.IntType;
 import org.apache.paimon.types.VarCharType;
 import org.apache.paimon.utils.RoaringBitmap32;
+import org.apache.paimon.utils.StringUtils;
 
 import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
@@ -148,6 +149,41 @@ public class BitmapFileIndexTest {
         return bitmapFileIndex.createReader(localSeekableInputStream, 0, 0);
     }
 
+    @Test
+    public void testV2EntryLargerThanBlockSize() throws Exception {
+        FieldRef fieldRef = new FieldRef(0, "", DataTypes.STRING());
+        // "big" serializes to more than the default 16kb index-block-size, so 
it cannot
+        // share a block with any other key; the writer must still produce a 
readable
+        // index instead of failing with "index fail". "a" and "b" pack into 
the first
+        // block, so the ordinary size check is exercised too.
+        BinaryString big = BinaryString.fromString(StringUtils.repeat("x", 
20_000));
+        BinaryString a = BinaryString.fromString("a");
+        BinaryString b = BinaryString.fromString("b");
+        Object[] dataColumn = {big, null, a, big, b};
+        FileIndexReader reader =
+                createTestReaderOnWriter(
+                        BitmapFileIndex.VERSION_2,
+                        16 * 1024,
+                        DataTypes.STRING(),
+                        writer -> {
+                            for (Object o : dataColumn) {
+                                writer.write(o);
+                            }
+                        });
+        assert ((BitmapIndexResult) reader.visitEqual(fieldRef, big))
+                .get()
+                .equals(RoaringBitmap32.bitmapOf(0, 3));
+        assert ((BitmapIndexResult) reader.visitEqual(fieldRef, a))
+                .get()
+                .equals(RoaringBitmap32.bitmapOf(2));
+        assert ((BitmapIndexResult) reader.visitEqual(fieldRef, b))
+                .get()
+                .equals(RoaringBitmap32.bitmapOf(4));
+        assert ((BitmapIndexResult) reader.visitIsNull(fieldRef))
+                .get()
+                .equals(RoaringBitmap32.bitmapOf(1));
+    }
+
     private void testStringType(int version) throws Exception {
         FieldRef fieldRef = new FieldRef(0, "", DataTypes.STRING());
         BinaryString a = BinaryString.fromString("a");

Reply via email to