use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class ImplementFilterRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final Collection<? extends RecordQueryPlan> innerPlans = bindings.get(innerPlansMatcher);
final Quantifier.ForEach innerQuantifier = bindings.get(innerQuantifierMatcher);
final List<? extends QueryPredicate> queryPredicates = bindings.getAll(filterMatcher);
final GroupExpressionRef<? extends RecordQueryPlan> referenceOverPlans = GroupExpressionRef.from(innerPlans);
if (queryPredicates.stream().allMatch(QueryPredicate::isTautology)) {
call.yield(referenceOverPlans);
} else {
call.yield(GroupExpressionRef.of(new RecordQueryPredicatesFilterPlan(Quantifier.physicalBuilder().morphFrom(innerQuantifier).build(referenceOverPlans), queryPredicates)));
}
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class PushInterestingOrderingThroughSortRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final LogicalSortExpression logicalSortExpression = bindings.get(root);
final ExpressionRef<? extends RelationalExpression> lowerRef = bindings.get(lowerRefMatcher);
final KeyExpression sortKeyExpression = logicalSortExpression.getSort();
if (sortKeyExpression == null) {
call.pushRequirement(lowerRef, OrderingAttribute.ORDERING, ImmutableSet.of(RequestedOrdering.preserve()));
} else {
final List<KeyExpression> normalizedSortKeys = sortKeyExpression.normalizeKeyForPositions();
final ImmutableList.Builder<KeyPart> keyPartBuilder = ImmutableList.builder();
for (final KeyExpression keyExpression : normalizedSortKeys) {
keyPartBuilder.add(KeyPart.of(keyExpression, logicalSortExpression.isReverse()));
}
final var orderings = ImmutableSet.of(new RequestedOrdering(keyPartBuilder.build(), RequestedOrdering.Distinctness.PRESERVE_DISTINCTNESS));
call.pushRequirement(lowerRef, OrderingAttribute.ORDERING, orderings);
}
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class PushReferencedFieldsThroughDistinctRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final ExpressionRef<? extends RelationalExpression> lowerRef = bindings.get(lowerRefMatcher);
final Optional<ReferencedFields> referencedFieldsOptional = call.getInterestingProperty(ReferencedFieldsAttribute.REFERENCED_FIELDS);
if (!referencedFieldsOptional.isPresent()) {
return;
}
call.pushRequirement(lowerRef, ReferencedFieldsAttribute.REFERENCED_FIELDS, referencedFieldsOptional.get());
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings in project fdb-record-layer by FoundationDB.
the class PushReferencedFieldsThroughSelectRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final PlannerBindings bindings = call.getBindings();
final SelectExpression selectExpression = bindings.get(root);
final List<? extends QueryPredicate> predicates = bindings.getAll(predicateMatcher);
final Set<FieldValue> fieldValuesFromPredicates = RelationalExpressionWithPredicates.fieldValuesFromPredicates(predicates);
final Set<FieldValue> fieldValuesFromResultValues = selectExpression.getFieldValuesFromResultValues();
final ExpressionRef<? extends RelationalExpression> lowerRef = bindings.get(lowerRefMatcher);
final ImmutableSet<FieldValue> allReferencedValues = ImmutableSet.<FieldValue>builder().addAll(call.getInterestingProperty(ReferencedFieldsAttribute.REFERENCED_FIELDS).map(ReferencedFields::getReferencedFieldValues).orElse(ImmutableSet.of())).addAll(fieldValuesFromPredicates).addAll(fieldValuesFromResultValues).build();
call.pushRequirement(lowerRef, ReferencedFieldsAttribute.REFERENCED_FIELDS, new ReferencedFields(allReferencedValues));
}
use of com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings 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