This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch release-1.0
in repository https://gitbox.apache.org/repos/asf/paimon.git

commit b73192192269b4c9cf9b2e13db4264eac46aa390
Author: Jingsong Lee <[email protected]>
AuthorDate: Wed Dec 25 17:44:00 2024 +0800

    [core] SortLookupStoreWriter should support empty record (#4777)
---
 .../org/apache/paimon/lookup/sort/BlockWriter.java     |  5 ++++-
 .../paimon/lookup/sort/SortLookupStoreFactoryTest.java | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/lookup/sort/BlockWriter.java 
b/paimon-common/src/main/java/org/apache/paimon/lookup/sort/BlockWriter.java
index d4f48e9c79..340abac862 100644
--- a/paimon-common/src/main/java/org/apache/paimon/lookup/sort/BlockWriter.java
+++ b/paimon-common/src/main/java/org/apache/paimon/lookup/sort/BlockWriter.java
@@ -83,8 +83,11 @@ public class BlockWriter {
 
     public MemorySlice finish() throws IOException {
         if (positions.isEmpty()) {
-            throw new IllegalStateException();
+            // Do not use alignment mode, as it is impossible to calculate how 
many records are
+            // inside when reading
+            aligned = false;
         }
+
         if (aligned) {
             block.writeInt(alignedSize);
         } else {
diff --git 
a/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java
 
b/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java
index 7ba3f8283a..354283a1d4 100644
--- 
a/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java
+++ 
b/paimon-common/src/test/java/org/apache/paimon/lookup/sort/SortLookupStoreFactoryTest.java
@@ -114,6 +114,24 @@ public class SortLookupStoreFactoryTest {
         assertThat(cacheManager.indexCache().asMap()).isEmpty();
     }
 
+    @TestTemplate
+    public void testEmpty() throws IOException {
+        CacheManager cacheManager = new 
CacheManager(MemorySize.ofMebiBytes(1));
+        SortLookupStoreFactory factory =
+                new SortLookupStoreFactory(Comparator.naturalOrder(), 
cacheManager, 1024, compress);
+
+        SortLookupStoreWriter writer =
+                factory.createWriter(file, 
createBloomFiler(bloomFilterEnabled));
+        Context context = writer.close();
+
+        SortLookupStoreReader reader = factory.createReader(file, context);
+        byte[] bytes = toBytes(rnd.nextInt(VALUE_COUNT));
+        assertThat(reader.lookup(bytes)).isNull();
+        reader.close();
+        assertThat(cacheManager.dataCache().asMap()).isEmpty();
+        assertThat(cacheManager.indexCache().asMap()).isEmpty();
+    }
+
     @TestTemplate
     public void testIntKey() throws IOException {
         RowCompactedSerializer keySerializer =

Reply via email to