Skip to content

Commit

Permalink
[core] Fix offset bug of bitmap index (apache#3911)
Browse files Browse the repository at this point in the history
  • Loading branch information
hang8929201 authored Aug 6, 2024
1 parent 84732cd commit 1a3debc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ public byte[] serializedBytes() {
// 2.build bitmap file index meta
LinkedHashMap<Object, Integer> bitmapOffsets = new LinkedHashMap<>();
LinkedList<byte[]> serializeBitmaps = new LinkedList<>();
int[] offsetRef = {nullBitmap.isEmpty() ? 0 : nullBitmapBytes.length};
int[] offsetRef = {
nullBitmap.isEmpty() || nullBitmap.getCardinality() == 1
? 0
: nullBitmapBytes.length
};
id2bitmap.forEach(
(k, v) -> {
if (v.getCardinality() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,30 @@ public void testBitmapIndex2() {
(BitmapIndexResultLazy) reader.visitNotIn(fieldRef, Arrays.asList(1, 0));
assert result5.get().equals(RoaringBitmap32.bitmapOf(2));
}

@Test
public void testBitmapIndex3() {

IntType intType = new IntType();
FieldRef fieldRef = new FieldRef(0, "", intType);
BitmapFileIndex bitmapFileIndex = new BitmapFileIndex(intType, null);
FileIndexWriter writer = bitmapFileIndex.createWriter();

// test only one null-value
Object[] arr = {1, 2, 1, 2, 1, 3, null};

for (Object o : arr) {
writer.write(o);
}
byte[] bytes = writer.serializedBytes();
ByteArraySeekableStream seekableStream = new ByteArraySeekableStream(bytes);
FileIndexReader reader = bitmapFileIndex.createReader(seekableStream, 0, bytes.length);

BitmapIndexResultLazy result1 = (BitmapIndexResultLazy) reader.visitEqual(fieldRef, 1);
assert result1.get().equals(RoaringBitmap32.bitmapOf(0, 2, 4));

// test read singleton bitmap
BitmapIndexResultLazy result2 = (BitmapIndexResultLazy) reader.visitIsNull(fieldRef);
assert result2.get().equals(RoaringBitmap32.bitmapOf(6));
}
}

0 comments on commit 1a3debc

Please sign in to comment.