Search in sources :

Example 1 with QueryComponentPredicate

use of com.apple.foundationdb.record.query.predicates.QueryComponentPredicate in project fdb-record-layer by FoundationDB.

the class PushFilterThroughFetchRule method pushLeafPredicate.

@Nullable
private QueryPredicate pushLeafPredicate(@Nonnull RecordQueryFetchFromPartialRecordPlan fetchPlan, @Nonnull CorrelationIdentifier newInnerAlias, @Nonnull final QueryPredicate leafPredicate) {
    if (leafPredicate instanceof QueryComponentPredicate) {
        // We cannot push these predicates. They always contain nesteds.
        return null;
    }
    if (!(leafPredicate instanceof PredicateWithValue)) {
        // appears to be pushable as is.
        return leafPredicate;
    }
    final PredicateWithValue predicateWithValue = (PredicateWithValue) leafPredicate;
    final Value value = predicateWithValue.getValue();
    final Optional<Value> pushedValueOptional = fetchPlan.pushValue(value, newInnerAlias);
    // We must return null to prevent pushing of this conjunct.
    return pushedValueOptional.map(predicateWithValue::withValue).orElse(null);
}
Also used : QueryComponentPredicate(com.apple.foundationdb.record.query.predicates.QueryComponentPredicate) PredicateWithValue(com.apple.foundationdb.record.query.predicates.PredicateWithValue) PredicateWithValue(com.apple.foundationdb.record.query.predicates.PredicateWithValue) Value(com.apple.foundationdb.record.query.predicates.Value) Nullable(javax.annotation.Nullable)

Example 2 with QueryComponentPredicate

use of com.apple.foundationdb.record.query.predicates.QueryComponentPredicate in project fdb-record-layer by FoundationDB.

the class ExpressionMatcherTest method anyRefMatcher.

@Test
public void anyRefMatcher() {
    // create a matcher and expression to match
    BindingMatcher<? extends ExpressionRef<? extends RelationalExpression>> matcher = ReferenceMatchers.anyRef();
    Quantifier.ForEach quantifier = Quantifier.forEach(GroupExpressionRef.of(new RecordQueryScanPlan(ScanComparisons.EMPTY, false)));
    ExpressionRef<RelationalExpression> root = GroupExpressionRef.of(new LogicalFilterExpression(ImmutableList.of(new QueryComponentPredicate(Query.field("test").equalsValue(5))), quantifier));
    // try to match to expression
    Optional<PlannerBindings> newBindings = matcher.bindMatches(PlannerBindings.empty(), root).findFirst();
    // check the the bindings are what we expect, and that none of the existing ones were clobbered
    assertTrue(newBindings.isPresent());
    PlannerBindings allBindings = newBindings.get().mergedWith(getExistingBindings());
    assertExistingBindingsSurvived(allBindings);
    assertTrue(newBindings.get().containsKey(matcher));
    assertTrue(allBindings.containsKey(matcher));
    assertEquals(root, allBindings.get(matcher));
}
Also used : RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) QueryComponentPredicate(com.apple.foundationdb.record.query.predicates.QueryComponentPredicate) LogicalFilterExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) Test(org.junit.jupiter.api.Test)

Aggregations

QueryComponentPredicate (com.apple.foundationdb.record.query.predicates.QueryComponentPredicate)2 RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)1 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)1 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)1 LogicalFilterExpression (com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression)1 PredicateWithValue (com.apple.foundationdb.record.query.predicates.PredicateWithValue)1 Value (com.apple.foundationdb.record.query.predicates.Value)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.jupiter.api.Test)1