Skip to content

Commit

Permalink
[bug] [file-index] Fix type bug when using Boolean in bitmap for file…
Browse files Browse the repository at this point in the history
… index (#5013)
  • Loading branch information
jerry-024 authored Feb 5, 2025
1 parent 1957230 commit 0d0793e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public ThrowableConsumer visitFloat() {
public ThrowableConsumer visitDouble() {
return o -> out.writeDouble((double) o);
}

@Override
public ThrowableConsumer visitBoolean() {
return o -> out.writeBoolean((Boolean) o);
}
});

out.writeInt(rowCount);
Expand Down Expand Up @@ -234,6 +239,11 @@ public ThrowableSupplier visitFloat() {
public ThrowableSupplier visitDouble() {
return in::readDouble;
}

@Override
public ThrowableSupplier visitBoolean() {
return in::readBoolean;
}
});

rowCount = in.readInt();
Expand Down Expand Up @@ -275,6 +285,8 @@ public abstract static class DataTypeVisitorAdapter<R> implements DataTypeVisito

public abstract R visitDouble();

public abstract R visitBoolean();

@Override
public final R visit(CharType charType) {
return visitBinaryString();
Expand All @@ -287,7 +299,7 @@ public final R visit(VarCharType varCharType) {

@Override
public final R visit(BooleanType booleanType) {
return visitByte();
return visitBoolean();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import org.apache.paimon.fileindex.bitmap.BitmapIndexResult;
import org.apache.paimon.fs.ByteArraySeekableStream;
import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.types.BooleanType;
import org.apache.paimon.types.IntType;
import org.apache.paimon.types.VarCharType;
import org.apache.paimon.utils.RoaringBitmap32;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -138,4 +140,29 @@ public void testBitmapIndex3() {
BitmapIndexResult result2 = (BitmapIndexResult) reader.visitIsNull(fieldRef);
assert result2.get().equals(RoaringBitmap32.bitmapOf(6));
}

@Test
void testBitmapIndexForBooleanType() {

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

Object[] arr = {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, 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);

BitmapIndexResult searchTrueResult =
(BitmapIndexResult) reader.visitEqual(fieldRef, Boolean.TRUE);
Assertions.assertThat(searchTrueResult.get()).isEqualTo(RoaringBitmap32.bitmapOf(0, 2));

BitmapIndexResult searchNullResult = (BitmapIndexResult) reader.visitIsNull(fieldRef);
Assertions.assertThat(searchNullResult.get()).isEqualTo(RoaringBitmap32.bitmapOf(4));
}
}

0 comments on commit 0d0793e

Please sign in to comment.