use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.
the class AdjustMatchRule method onMatch.
@Override
@SuppressWarnings("java:S135")
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final PartialMatch incompleteMatch = bindings.get(rootMatcher);
final ExpressionRef<? extends RelationalExpression> queryReference = incompleteMatch.getQueryRef();
final MatchCandidate matchCandidate = incompleteMatch.getMatchCandidate();
final SetMultimap<ExpressionRef<? extends RelationalExpression>, RelationalExpression> refToExpressionMap = matchCandidate.findReferencingExpressions(ImmutableList.of(queryReference));
for (final Map.Entry<ExpressionRef<? extends RelationalExpression>, RelationalExpression> entry : refToExpressionMap.entries()) {
final ExpressionRef<? extends RelationalExpression> candidateReference = entry.getKey();
final RelationalExpression candidateExpression = entry.getValue();
matchWithCandidate(incompleteMatch, candidateExpression).ifPresent(matchInfo -> call.yieldPartialMatch(incompleteMatch.getBoundAliasMap(), matchCandidate, incompleteMatch.getQueryExpression(), candidateReference, matchInfo));
}
}
use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression 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.RelationalExpression in project fdb-record-layer by FoundationDB.
the class CombineFilterRuleTest method combineFilter.
@Test
public void combineFilter() {
for (RecordQueryPlan basePlan : basePlans) {
QueryComponent filter1 = Query.field("testField").equalsValue(5);
QueryComponent filter2 = Query.field("testField2").equalsValue(10);
GroupExpressionRef<RelationalExpression> root = GroupExpressionRef.of(buildLogicalFilter(filter1, buildLogicalFilter(filter2, basePlan)));
TestRuleExecution execution = TestRuleExecution.applyRule(blankContext, rule, root);
assertTrue(execution.isRuleMatched());
assertTrue(execution.getResult().containsInMemo(buildLogicalFilter(Query.and(filter1, filter2), basePlan)));
}
}
use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.
the class CombineFilterRuleTest method doesNotCoalesce.
@Test
public void doesNotCoalesce() {
for (RecordQueryPlan basePlan : basePlans) {
QueryComponent filter1 = Query.field("testField").equalsValue(5);
GroupExpressionRef<RelationalExpression> root = GroupExpressionRef.of(buildLogicalFilter(filter1, buildLogicalFilter(filter1, basePlan)));
TestRuleExecution execution = TestRuleExecution.applyRule(blankContext, rule, root);
assertTrue(execution.isRuleMatched());
// this rule should not try to coalesce the two filters
assertTrue(root.containsInMemo(buildLogicalFilter(Query.and(filter1, filter1), basePlan)));
assertFalse(root.containsInMemo(buildLogicalFilter(filter1, basePlan)));
}
}
use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.
the class TestRuleExecution method applyRule.
public static TestRuleExecution applyRule(@Nonnull PlanContext context, @Nonnull PlannerRule<? extends RelationalExpression> rule, @Nonnull GroupExpressionRef<RelationalExpression> group) {
boolean ruleMatched = false;
for (RelationalExpression expression : group.getMembers()) {
final Iterator<CascadesRuleCall> ruleCalls = rule.getMatcher().bindMatches(PlannerBindings.empty(), expression).map(bindings -> new CascadesRuleCall(context, rule, group, Quantifiers.AliasResolver.withRoot(group), bindings)).iterator();
while (ruleCalls.hasNext()) {
ruleCalls.next().run();
ruleMatched = true;
}
}
return new TestRuleExecution(ruleMatched, group);
}
Aggregations