Skip to content

Commit

Permalink
[core] Rename BitmapIndexResultLazy to BitmapIndexResult
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Nov 11, 2024
1 parent 34153b3 commit c25eeef
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public FileIndexResult visitNotEqual(FieldRef fieldRef, Object literal) {

@Override
public FileIndexResult visitIn(FieldRef fieldRef, List<Object> literals) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
readInternalMeta(fieldRef.type());
return getInListResultBitmap(literals);
Expand All @@ -197,7 +197,7 @@ public FileIndexResult visitIn(FieldRef fieldRef, List<Object> literals) {

@Override
public FileIndexResult visitNotIn(FieldRef fieldRef, List<Object> literals) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
readInternalMeta(fieldRef.type());
RoaringBitmap32 bitmap = getInListResultBitmap(literals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,31 @@
import java.util.function.Supplier;

/** bitmap file index result. */
public class BitmapIndexResultLazy extends LazyField<RoaringBitmap32> implements FileIndexResult {
public class BitmapIndexResult extends LazyField<RoaringBitmap32> implements FileIndexResult {

public BitmapIndexResultLazy(Supplier<RoaringBitmap32> supplier) {
public BitmapIndexResult(Supplier<RoaringBitmap32> supplier) {
super(supplier);
}

@Override
public boolean remain() {
return !get().isEmpty();
}

@Override
public FileIndexResult and(FileIndexResult fileIndexResult) {
if (fileIndexResult instanceof BitmapIndexResultLazy) {
return new BitmapIndexResultLazy(
() ->
RoaringBitmap32.and(
get(), ((BitmapIndexResultLazy) fileIndexResult).get()));
if (fileIndexResult instanceof BitmapIndexResult) {
return new BitmapIndexResult(
() -> RoaringBitmap32.and(get(), ((BitmapIndexResult) fileIndexResult).get()));
}
return FileIndexResult.super.and(fileIndexResult);
}

@Override
public FileIndexResult or(FileIndexResult fileIndexResult) {
if (fileIndexResult instanceof BitmapIndexResultLazy) {
return new BitmapIndexResultLazy(
() ->
RoaringBitmap32.or(
get(), ((BitmapIndexResultLazy) fileIndexResult).get()));
if (fileIndexResult instanceof BitmapIndexResult) {
return new BitmapIndexResult(
() -> RoaringBitmap32.or(get(), ((BitmapIndexResult) fileIndexResult).get()));
}
return FileIndexResult.super.and(fileIndexResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.paimon.fileindex.FileIndexResult;
import org.apache.paimon.fileindex.FileIndexWriter;
import org.apache.paimon.fileindex.FileIndexer;
import org.apache.paimon.fileindex.bitmap.BitmapIndexResultLazy;
import org.apache.paimon.fileindex.bitmap.BitmapIndexResult;
import org.apache.paimon.fs.SeekableInputStream;
import org.apache.paimon.options.Options;
import org.apache.paimon.predicate.FieldRef;
Expand Down Expand Up @@ -208,7 +208,7 @@ public Reader(

@Override
public FileIndexResult visitIsNull(FieldRef fieldRef) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
RoaringBitmap32 bitmap =
RoaringBitmap32.or(positive.isNotNull(), negative.isNotNull());
Expand All @@ -219,7 +219,7 @@ public FileIndexResult visitIsNull(FieldRef fieldRef) {

@Override
public FileIndexResult visitIsNotNull(FieldRef fieldRef) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> RoaringBitmap32.or(positive.isNotNull(), negative.isNotNull()));
}

Expand All @@ -235,7 +235,7 @@ public FileIndexResult visitNotEqual(FieldRef fieldRef, Object literal) {

@Override
public FileIndexResult visitIn(FieldRef fieldRef, List<Object> literals) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() ->
literals.stream()
.map(valueMapper)
Expand All @@ -254,7 +254,7 @@ public FileIndexResult visitIn(FieldRef fieldRef, List<Object> literals) {

@Override
public FileIndexResult visitNotIn(FieldRef fieldRef, List<Object> literals) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
RoaringBitmap32 ebm =
RoaringBitmap32.or(positive.isNotNull(), negative.isNotNull());
Expand All @@ -278,7 +278,7 @@ public FileIndexResult visitNotIn(FieldRef fieldRef, List<Object> literals) {

@Override
public FileIndexResult visitLessThan(FieldRef fieldRef, Object literal) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
Long value = valueMapper.apply(literal);
if (value < 0) {
Expand All @@ -291,7 +291,7 @@ public FileIndexResult visitLessThan(FieldRef fieldRef, Object literal) {

@Override
public FileIndexResult visitLessOrEqual(FieldRef fieldRef, Object literal) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
Long value = valueMapper.apply(literal);
if (value < 0) {
Expand All @@ -304,7 +304,7 @@ public FileIndexResult visitLessOrEqual(FieldRef fieldRef, Object literal) {

@Override
public FileIndexResult visitGreaterThan(FieldRef fieldRef, Object literal) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
Long value = valueMapper.apply(literal);
if (value < 0) {
Expand All @@ -318,7 +318,7 @@ public FileIndexResult visitGreaterThan(FieldRef fieldRef, Object literal) {

@Override
public FileIndexResult visitGreaterOrEqual(FieldRef fieldRef, Object literal) {
return new BitmapIndexResultLazy(
return new BitmapIndexResult(
() -> {
Long value = valueMapper.apply(literal);
if (value < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.paimon.fileindex.FileIndexReader;
import org.apache.paimon.fileindex.FileIndexWriter;
import org.apache.paimon.fileindex.bitmap.BitmapFileIndex;
import org.apache.paimon.fileindex.bitmap.BitmapIndexResultLazy;
import org.apache.paimon.fileindex.bitmap.BitmapIndexResult;
import org.apache.paimon.fs.ByteArraySeekableStream;
import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.types.IntType;
Expand Down Expand Up @@ -63,21 +63,21 @@ public void testBitmapIndex1() {
ByteArraySeekableStream seekableStream = new ByteArraySeekableStream(bytes);
FileIndexReader reader = bitmapFileIndex.createReader(seekableStream, 0, bytes.length);

BitmapIndexResultLazy result1 =
(BitmapIndexResultLazy) reader.visitEqual(fieldRef, BinaryString.fromString("a"));
BitmapIndexResult result1 =
(BitmapIndexResult) reader.visitEqual(fieldRef, BinaryString.fromString("a"));
assert result1.get().equals(RoaringBitmap32.bitmapOf(0, 4));

BitmapIndexResultLazy result2 =
(BitmapIndexResultLazy) reader.visitEqual(fieldRef, BinaryString.fromString("b"));
BitmapIndexResult result2 =
(BitmapIndexResult) reader.visitEqual(fieldRef, BinaryString.fromString("b"));
assert result2.get().equals(RoaringBitmap32.bitmapOf(2));

BitmapIndexResultLazy result3 = (BitmapIndexResultLazy) reader.visitIsNull(fieldRef);
BitmapIndexResult result3 = (BitmapIndexResult) reader.visitIsNull(fieldRef);
assert result3.get().equals(RoaringBitmap32.bitmapOf(1, 3));

BitmapIndexResultLazy result4 = (BitmapIndexResultLazy) result1.and(result2);
BitmapIndexResult result4 = (BitmapIndexResult) result1.and(result2);
assert result4.get().equals(RoaringBitmap32.bitmapOf());

BitmapIndexResultLazy result5 = (BitmapIndexResultLazy) result1.or(result2);
BitmapIndexResult result5 = (BitmapIndexResult) result1.or(result2);
assert result5.get().equals(RoaringBitmap32.bitmapOf(0, 2, 4));
}

Expand All @@ -95,21 +95,21 @@ public void testBitmapIndex2() {
ByteArraySeekableStream seekableStream = new ByteArraySeekableStream(bytes);
FileIndexReader reader = bitmapFileIndex.createReader(seekableStream, 0, bytes.length);

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

BitmapIndexResultLazy result2 = (BitmapIndexResultLazy) reader.visitIsNull(fieldRef);
BitmapIndexResult result2 = (BitmapIndexResult) reader.visitIsNull(fieldRef);
assert result2.get().equals(RoaringBitmap32.bitmapOf(2));

BitmapIndexResultLazy result3 = (BitmapIndexResultLazy) reader.visitIsNotNull(fieldRef);
BitmapIndexResult result3 = (BitmapIndexResult) reader.visitIsNotNull(fieldRef);
assert result3.get().equals(RoaringBitmap32.bitmapOf(0, 1));

BitmapIndexResultLazy result4 =
(BitmapIndexResultLazy) reader.visitNotIn(fieldRef, Arrays.asList(1, 2));
BitmapIndexResult result4 =
(BitmapIndexResult) reader.visitNotIn(fieldRef, Arrays.asList(1, 2));
assert result4.get().equals(RoaringBitmap32.bitmapOf(0, 2));

BitmapIndexResultLazy result5 =
(BitmapIndexResultLazy) reader.visitNotIn(fieldRef, Arrays.asList(1, 0));
BitmapIndexResult result5 =
(BitmapIndexResult) reader.visitNotIn(fieldRef, Arrays.asList(1, 0));
assert result5.get().equals(RoaringBitmap32.bitmapOf(2));
}

Expand All @@ -131,11 +131,11 @@ public void testBitmapIndex3() {
ByteArraySeekableStream seekableStream = new ByteArraySeekableStream(bytes);
FileIndexReader reader = bitmapFileIndex.createReader(seekableStream, 0, bytes.length);

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

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

0 comments on commit c25eeef

Please sign in to comment.