use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class InComparisonToExplodeRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final SelectExpression selectExpression = bindings.get(root);
// we don't need iteration stability
final List<? extends ValuePredicate> inPredicatesList = bindings.getAll(inPredicateMatcher);
if (inPredicatesList.isEmpty()) {
return;
}
final Set<QueryPredicate> inPredicates = Sets.newIdentityHashSet();
inPredicates.addAll(inPredicatesList);
final ImmutableList.Builder<Quantifier> transformedQuantifiers = ImmutableList.builder();
final ImmutableList.Builder<QueryPredicate> transformedPredicates = ImmutableList.builder();
for (final QueryPredicate predicate : selectExpression.getPredicates()) {
if (inPredicates.contains(predicate)) {
final ValuePredicate valuePredicate = (ValuePredicate) predicate;
final Comparisons.Comparison comparison = valuePredicate.getComparison();
Verify.verify(comparison.getType() == Comparisons.Type.IN);
final ExplodeExpression explodeExpression;
if (comparison instanceof Comparisons.ListComparison) {
explodeExpression = new ExplodeExpression(new LiteralValue<>(comparison.getComparand()));
} else if (comparison instanceof Comparisons.ParameterComparison) {
explodeExpression = new ExplodeExpression(QuantifiedColumnValue.of(CorrelationIdentifier.of(((Comparisons.ParameterComparison) comparison).getParameter()), 0));
} else {
throw new RecordCoreException("unknown in comparison " + comparison.getClass().getSimpleName());
}
final Quantifier.ForEach newQuantifier = Quantifier.forEach(GroupExpressionRef.of(explodeExpression));
transformedPredicates.add(new ValuePredicate(((ValuePredicate) predicate).getValue(), new Comparisons.ParameterComparison(Comparisons.Type.EQUALS, Bindings.Internal.CORRELATION.bindingName(newQuantifier.getAlias().toString()), Bindings.Internal.CORRELATION)));
transformedQuantifiers.add(newQuantifier);
} else {
transformedPredicates.add(predicate);
}
}
transformedQuantifiers.addAll(bindings.getAll(innerQuantifierMatcher));
call.yield(call.ref(new SelectExpression(selectExpression.getResultValues(), transformedQuantifiers.build(), transformedPredicates.build())));
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class OrToLogicalUnionRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final SelectExpression selectExpression = bindings.get(root);
final List<? extends Value> resultValues = selectExpression.getResultValues();
final List<? extends Quantifier> quantifiers = bindings.getAll(qunMatcher);
final List<? extends QueryPredicate> orTermPredicates = bindings.getAll(orTermPredicateMatcher);
final List<ExpressionRef<RelationalExpression>> relationalExpressionRefs = new ArrayList<>(orTermPredicates.size());
for (final QueryPredicate orTermPredicate : orTermPredicates) {
relationalExpressionRefs.add(call.ref(new SelectExpression(resultValues, quantifiers, ImmutableList.of(orTermPredicate))));
}
call.yield(GroupExpressionRef.of(new LogicalUnionExpression(Quantifiers.forEachQuantifiers(relationalExpressionRefs))));
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class PushInJoinThroughFetchRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final RecordQueryInJoinPlan inJoinPlan = bindings.get(getMatcher());
final RecordQueryFetchFromPartialRecordPlan fetchPlan = bindings.get(fetchPlanMatcher);
final RecordQueryPlan innerPlan = bindings.get(innerPlanMatcher);
final RecordQueryPlanWithChild pushedInJoinPlan = inJoinPlan.withChild(innerPlan);
final var newFetchPlan = new RecordQueryFetchFromPartialRecordPlan(pushedInJoinPlan, fetchPlan.getPushValueFunction());
call.yield(call.ref(newFetchPlan));
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class PushInterestingOrderingThroughDistinctRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final Optional<Set<RequestedOrdering>> requestedOrderingOptionals = call.getInterestingProperty(OrderingAttribute.ORDERING);
if (requestedOrderingOptionals.isEmpty()) {
return;
}
final PlannerBindings bindings = call.getBindings();
final ExpressionRef<? extends RelationalExpression> lowerRef = bindings.get(lowerRefMatcher);
call.pushRequirement(lowerRef, OrderingAttribute.ORDERING, requestedOrderingOptionals.get());
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings 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));
}
}
Aggregations