Search in sources :

Example 1 with BoundMatch

use of com.apple.foundationdb.record.query.plan.temp.matching.BoundMatch 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)

Example 2 with BoundMatch

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

the class MatchLeafRule method onMatch.

@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
    final PlanContext context = call.getContext();
    final RelationalExpression expression = call.get(root);
    // iterate through all candidates known to the context
    for (final MatchCandidate matchCandidate : context.getMatchCandidates()) {
        final ExpressionRefTraversal traversal = matchCandidate.getTraversal();
        final Set<ExpressionRef<? extends RelationalExpression>> leafRefs = traversal.getLeafReferences();
        // iterate through all leaf references in all
        for (final ExpressionRef<? extends RelationalExpression> leafRef : leafRefs) {
            for (final RelationalExpression leafMember : leafRef.getMembers()) {
                // expressions.
                if (leafMember.getQuantifiers().isEmpty()) {
                    final Iterable<BoundMatch<MatchInfo>> boundMatchInfos = matchWithCandidate(expression, leafMember);
                    // yield any match to the planner
                    boundMatchInfos.forEach(boundMatchInfo -> call.yieldPartialMatch(boundMatchInfo.getAliasMap(), matchCandidate, expression, leafRef, boundMatchInfo.getMatchResult()));
                }
            }
        }
    }
}
Also used : RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) ExpressionRefTraversal(com.apple.foundationdb.record.query.plan.temp.ExpressionRefTraversal) ExpressionRef(com.apple.foundationdb.record.query.plan.temp.ExpressionRef) PlanContext(com.apple.foundationdb.record.query.plan.temp.PlanContext) BoundMatch(com.apple.foundationdb.record.query.plan.temp.matching.BoundMatch) MatchCandidate(com.apple.foundationdb.record.query.plan.temp.MatchCandidate)

Aggregations

ExpressionRef (com.apple.foundationdb.record.query.plan.temp.ExpressionRef)2 MatchCandidate (com.apple.foundationdb.record.query.plan.temp.MatchCandidate)2 RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)2 BoundMatch (com.apple.foundationdb.record.query.plan.temp.matching.BoundMatch)2 AliasMap (com.apple.foundationdb.record.query.plan.temp.AliasMap)1 ExpressionRefTraversal (com.apple.foundationdb.record.query.plan.temp.ExpressionRefTraversal)1 IdentityBiMap (com.apple.foundationdb.record.query.plan.temp.IdentityBiMap)1 LinkedIdentitySet (com.apple.foundationdb.record.query.plan.temp.LinkedIdentitySet)1 PlanContext (com.apple.foundationdb.record.query.plan.temp.PlanContext)1 PlannerBindings (com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings)1 Map (java.util.Map)1