Search in sources :

Example 21 with PlannerBindings

use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.

the class ImplementUnorderedUnionRule method onMatch.

@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
    final PlannerBindings bindings = call.getBindings();
    final List<? extends Collection<? extends RecordQueryPlan>> groupedPlansByLeg = bindings.getAll(unionLegPlansMatcher);
    final ImmutableList<Quantifier.Physical> quantifiers = groupedPlansByLeg.stream().map(GroupExpressionRef::from).map(Quantifier::physical).collect(ImmutableList.toImmutableList());
    call.yield(call.ref(RecordQueryUnorderedUnionPlan.fromQuantifiers(quantifiers)));
}
Also used : PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) GroupExpressionRef(com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef)

Example 22 with PlannerBindings

use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.

the class MatchIntermediateRule method onMatch.

@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
    final PlannerBindings bindings = call.getBindings();
    final RelationalExpression expression = bindings.get(root);
    final List<? extends Quantifier> quantifiers = bindings.getAll(quantifierMatcher);
    final ImmutableList<? extends ExpressionRef<? extends RelationalExpression>> rangesOverRefs = quantifiers.stream().map(Quantifier::getRangesOver).collect(ImmutableList.toImmutableList());
    // form union of all possible match candidates that this rule application should look at
    final Set<MatchCandidate> childMatchCandidates = new LinkedIdentitySet<>();
    for (int i = 0; i < rangesOverRefs.size(); i++) {
        final ExpressionRef<? extends RelationalExpression> rangesOverGroup = rangesOverRefs.get(i);
        childMatchCandidates.addAll(rangesOverGroup.getMatchCandidates());
    }
    // go through all match candidates
    for (final MatchCandidate matchCandidate : childMatchCandidates) {
        final SetMultimap<ExpressionRef<? extends RelationalExpression>, RelationalExpression> refToExpressionMap = matchCandidate.findReferencingExpressions(rangesOverRefs);
        // go through all reference paths, i.e., (ref, expression) pairs
        for (final Map.Entry<ExpressionRef<? extends RelationalExpression>, RelationalExpression> entry : refToExpressionMap.entries()) {
            final ExpressionRef<? extends RelationalExpression> candidateReference = entry.getKey();
            final RelationalExpression candidateExpression = entry.getValue();
            // match this expression with the candidate expression and yield zero to n new partial matches
            final Iterable<BoundMatch<MatchInfo>> boundMatchInfos = matchWithCandidate(expression, matchCandidate, candidateExpression);
            boundMatchInfos.forEach(boundMatchInfo -> call.yieldPartialMatch(boundMatchInfo.getAliasMap(), matchCandidate, expression, candidateReference, boundMatchInfo.getMatchResult()));
        }
    }
}
Also used : RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) BoundMatch(com.apple.foundationdb.record.query.plan.temp.matching.BoundMatch) ExpressionRef(com.apple.foundationdb.record.query.plan.temp.ExpressionRef) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) MatchCandidate(com.apple.foundationdb.record.query.plan.temp.MatchCandidate) Map(java.util.Map) IdentityBiMap(com.apple.foundationdb.record.query.plan.temp.IdentityBiMap) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) LinkedIdentitySet(com.apple.foundationdb.record.query.plan.temp.LinkedIdentitySet)

Aggregations

PlannerBindings (com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings)22 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)11 ImmutableList (com.google.common.collect.ImmutableList)9 QueryPredicate (com.apple.foundationdb.record.query.predicates.QueryPredicate)8 API (com.apple.foundationdb.annotation.API)7 ExpressionRef (com.apple.foundationdb.record.query.plan.temp.ExpressionRef)7 GroupExpressionRef (com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef)7 PlannerRule (com.apple.foundationdb.record.query.plan.temp.PlannerRule)7 PlannerRuleCall (com.apple.foundationdb.record.query.plan.temp.PlannerRuleCall)7 BindingMatcher (com.apple.foundationdb.record.query.plan.temp.matchers.BindingMatcher)7 Nonnull (javax.annotation.Nonnull)7 List (java.util.List)6 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)5 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)5 Set (java.util.Set)5 RecordQueryFetchFromPartialRecordPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryFetchFromPartialRecordPlan)4 CorrelationIdentifier (com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier)4 MultiMatcher.all (com.apple.foundationdb.record.query.plan.temp.matchers.MultiMatcher.all)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 Collection (java.util.Collection)4