use of com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression 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));
}
use of com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression in project fdb-record-layer by FoundationDB.
the class ExpressionMatcherTest method treeDescentWithMixedBindings.
@Test
public void treeDescentWithMixedBindings() {
// build a relatively complicated matcher
BindingMatcher<? extends ExpressionRef<? extends RelationalExpression>> filterLeafMatcher = ReferenceMatchers.anyRef();
BindingMatcher<QueryPredicate> predicateMatcher = QueryPredicateMatchers.anyPredicate();
final BindingMatcher<LogicalFilterExpression> filterPlanMatcher = RelationalExpressionMatchers.logicalFilterExpression(MultiMatcher.AllMatcher.all(predicateMatcher), AnyMatcher.any(QuantifierMatchers.forEachQuantifierOverRef(filterLeafMatcher)));
BindingMatcher<RecordQueryScanPlan> scanMatcher = RecordQueryPlanMatchers.scanPlan();
BindingMatcher<LogicalUnionExpression> matcher = RelationalExpressionMatchers.logicalUnionExpression(ListMatcher.exactly(QuantifierMatchers.forEachQuantifier(filterPlanMatcher), QuantifierMatchers.forEachQuantifier(scanMatcher)));
// build a relatively complicated expression
QueryComponent andBranch1 = Query.field("field1").greaterThan(6);
QueryComponent andBranch2 = Query.field("field2").equalsParameter("param");
IndexScanParameters fullValueScan = IndexScanComparisons.byValue();
final Quantifier.ForEach quantifier = Quantifier.forEach(GroupExpressionRef.of(new RecordQueryIndexPlan("an_index", fullValueScan, true)));
LogicalFilterExpression filterPlan = new LogicalFilterExpression(Query.and(andBranch1, andBranch2).expand(quantifier.getAlias()).getPredicates(), quantifier);
RecordQueryScanPlan scanPlan = new RecordQueryScanPlan(ScanComparisons.EMPTY, true);
RelationalExpression root = new LogicalUnionExpression(Quantifiers.forEachQuantifiers(ImmutableList.of(GroupExpressionRef.of(filterPlan), GroupExpressionRef.of(scanPlan))));
assertTrue(filterPlanMatcher.bindMatches(PlannerBindings.empty(), filterPlan).findFirst().isPresent());
// try to bind
Optional<PlannerBindings> possibleBindings = matcher.bindMatches(PlannerBindings.empty(), root).findFirst();
// check that all the bindings match what we expect
assertTrue(possibleBindings.isPresent());
PlannerBindings bindings = possibleBindings.get().mergedWith(getExistingBindings());
assertEquals(root, bindings.get(matcher));
assertEquals(filterPlan, bindings.get(filterPlanMatcher));
assertEquals(scanPlan, bindings.get(scanMatcher));
assertEquals(filterPlan.getPredicates(), bindings.getAll(predicateMatcher));
// dereference
assertEquals(filterPlan.getInner().getRangesOver().get(), bindings.get(filterLeafMatcher).get());
}
use of com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression in project fdb-record-layer by FoundationDB.
the class CombineFilterRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final ExpressionRef<?> inner = bindings.get(innerMatcher);
final Quantifier.ForEach lowerQun = bindings.get(lowerQunMatcher);
final List<? extends QueryPredicate> lowerPreds = bindings.getAll(lowerMatcher);
final Quantifier.ForEach upperQun = call.get(upperQunMatcher);
final List<? extends QueryPredicate> upperPreds = bindings.getAll(upperMatcher);
final Quantifier.ForEach newUpperQun = Quantifier.forEach(inner, upperQun.getAlias());
final List<? extends QueryPredicate> newLowerPred = lowerPreds.stream().map(lowerPred -> lowerPred.rebase(Quantifiers.translate(lowerQun, newUpperQun))).collect(ImmutableList.toImmutableList());
call.yield(call.ref(new LogicalFilterExpression(Iterables.concat(upperPreds, newLowerPred), newUpperQun)));
}
Aggregations