Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public CompletableFuture<Optional<GlobalIndexResult>> visitIsNull(FieldRef field
return result;
}

@Override
public CompletableFuture<Optional<GlobalIndexResult>> visitIsNaN(FieldRef fieldRef) {
return result;
}

@Override
public CompletableFuture<Optional<GlobalIndexResult>> visitStartsWith(
FieldRef fieldRef, Object literal) {
Expand Down Expand Up @@ -127,6 +132,12 @@ public CompletableFuture<Optional<GlobalIndexResult>> visitBetween(
return result;
}

@Override
public CompletableFuture<Optional<GlobalIndexResult>> visitNotBetween(
FieldRef fieldRef, Object from, Object to) {
return result;
}

@Override
public void close() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.paimon.globalindex;

import org.apache.paimon.predicate.BatchVectorSearch;
import org.apache.paimon.predicate.FieldRef;
import org.apache.paimon.predicate.FullTextSearch;
import org.apache.paimon.predicate.FunctionVisitor;
import org.apache.paimon.predicate.LeafPredicate;
Expand All @@ -34,6 +35,23 @@
public interface GlobalIndexReader
extends FunctionVisitor<CompletableFuture<Optional<GlobalIndexResult>>>, Closeable {

@Override
default CompletableFuture<Optional<GlobalIndexResult>> visitIsNaN(FieldRef fieldRef) {
return CompletableFuture.completedFuture(Optional.empty());
}

@Override
default CompletableFuture<Optional<GlobalIndexResult>> visitBetween(
FieldRef fieldRef, Object from, Object to) {
return CompletableFuture.completedFuture(Optional.empty());
}

@Override
default CompletableFuture<Optional<GlobalIndexResult>> visitNotBetween(
FieldRef fieldRef, Object from, Object to) {
return CompletableFuture.completedFuture(Optional.empty());
}

@Override
default CompletableFuture<Optional<GlobalIndexResult>> visitAnd(
List<CompletableFuture<Optional<GlobalIndexResult>>> children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public CompletableFuture<Optional<GlobalIndexResult>> visitBetween(
return wrapped.visitBetween(fieldRef, from, to).thenApply(this::applyOffset);
}

@Override
public CompletableFuture<Optional<GlobalIndexResult>> visitNotBetween(
FieldRef fieldRef, Object from, Object to) {
return wrapped.visitNotBetween(fieldRef, from, to).thenApply(this::applyOffset);
}

@Override
public CompletableFuture<Optional<ScoredGlobalIndexResult>> visitVectorSearch(
VectorSearch vectorSearch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public CompletableFuture<Optional<GlobalIndexResult>> visitBetween(
return unionAsync(reader -> reader.visitBetween(fieldRef, from, to));
}

@Override
public CompletableFuture<Optional<GlobalIndexResult>> visitNotBetween(
FieldRef fieldRef, Object from, Object to) {
return unionAsync(reader -> reader.visitNotBetween(fieldRef, from, to));
}

@Override
public CompletableFuture<Optional<ScoredGlobalIndexResult>> visitVectorSearch(
VectorSearch vectorSearch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,75 @@ public CompletableFuture<Optional<GlobalIndexResult>> visitIsNotNull(
evaluator.close();
}

@Test
void testUnsupportedIsNaNFallsBack() {
RowType rowType =
new RowType(Collections.singletonList(new DataField(0, "a", DataTypes.DOUBLE())));
GlobalIndexEvaluator evaluator =
new GlobalIndexEvaluator(
rowType,
fieldId -> Collections.singletonList(new StubGlobalIndexReader(null)));

Optional<GlobalIndexResult> result =
evaluator.evaluate(new PredicateBuilder(rowType).isNaN(0));

assertThat(result).isEmpty();
evaluator.close();
}

@Test
void testNotBetweenThroughUnionAndOffset() {
RowType rowType = rowType();
GlobalIndexReader delegate =
new StubGlobalIndexReader(null) {
@Override
public CompletableFuture<Optional<GlobalIndexResult>> visitNotBetween(
FieldRef fieldRef, Object from, Object to) {
return CompletableFuture.completedFuture(Optional.of(resultOf(1, 3)));
}
};
GlobalIndexReader wrapped =
new UnionGlobalIndexReader(
Collections.singletonList(new OffsetGlobalIndexReader(delegate, 10L, 20L)));
GlobalIndexEvaluator evaluator =
new GlobalIndexEvaluator(rowType, fieldId -> Collections.singletonList(wrapped));
PredicateBuilder builder = new PredicateBuilder(rowType);

Optional<GlobalIndexResult> result =
evaluator.evaluate(builder.between(0, 1, 2).negate().get());

assertThat(result).isPresent();
assertBitmapContainsExactly(result.get().results(), 11L, 13L);
evaluator.close();
}

@Test
void testWrappedUnsupportedRangePredicatesFallBack() {
RowType rowType = rowType();
GlobalIndexReader wrapped =
new UnionGlobalIndexReader(
Collections.singletonList(
new OffsetGlobalIndexReader(
new StubGlobalIndexReader(null), 10L, 20L)));
GlobalIndexEvaluator evaluator =
new GlobalIndexEvaluator(rowType, fieldId -> Collections.singletonList(wrapped));
PredicateBuilder builder = new PredicateBuilder(rowType);

assertThat(evaluator.evaluate(builder.between(0, 1, 2).negate().get())).isEmpty();
assertThat(evaluator.evaluate(builder.between(0, 1, 2))).isEmpty();
evaluator.close();
}

@Test
void testConstantReaderReturnsFixedResultForIsNaNAndNotBetween() {
GlobalIndexResult expected = resultOf(1, 2);
GlobalIndexReader reader = new ConstantGlobalIndexReader(expected);
FieldRef fieldRef = new FieldRef(0, "a", DataTypes.DOUBLE());

assertThat(reader.visitIsNaN(fieldRef).join()).contains(expected);
assertThat(reader.visitNotBetween(fieldRef, 1, 2).join()).contains(expected);
}

@Test
void testNullPredicate() {
RowType rowType = rowType();
Expand Down
Loading