Skip to content

Commit

Permalink
[core] SortLookupStoreWriter should support empty record (apache#4777)
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi authored Dec 25, 2024
1 parent ffef316 commit 49a5bd2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ public int memory() {

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ public void testNormal() throws IOException {
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 =
Expand Down

0 comments on commit 49a5bd2

Please sign in to comment.