Search in sources :

Example 6 with PlannerBindings

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)));
    }
}
Also used : QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) RecordQueryPredicatesFilterPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPredicatesFilterPlan) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier)

Example 7 with PlannerBindings

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);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) KeyPart(com.apple.foundationdb.record.query.plan.temp.KeyPart) RequestedOrdering(com.apple.foundationdb.record.query.plan.temp.RequestedOrdering) LogicalSortExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalSortExpression)

Example 8 with PlannerBindings

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());
}
Also used : ReferencedFields(com.apple.foundationdb.record.query.plan.temp.ReferencedFieldsAttribute.ReferencedFields) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings)

Example 9 with PlannerBindings

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));
}
Also used : ReferencedFields(com.apple.foundationdb.record.query.plan.temp.ReferencedFieldsAttribute.ReferencedFields) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue)

Example 10 with PlannerBindings

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)));
}
Also used : PlannerRuleCall(com.apple.foundationdb.record.query.plan.temp.PlannerRuleCall) Iterables(com.google.common.collect.Iterables) PlannerRule(com.apple.foundationdb.record.query.plan.temp.PlannerRule) QueryPredicateMatchers.anyPredicate(com.apple.foundationdb.record.query.plan.temp.matchers.QueryPredicateMatchers.anyPredicate) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) MultiMatcher.all(com.apple.foundationdb.record.query.plan.temp.matchers.MultiMatcher.all) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) Quantifiers(com.apple.foundationdb.record.query.plan.temp.Quantifiers) LogicalFilterExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression) RelationalExpressionMatchers.logicalFilterExpression(com.apple.foundationdb.record.query.plan.temp.matchers.RelationalExpressionMatchers.logicalFilterExpression) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) ReferenceMatchers.anyRef(com.apple.foundationdb.record.query.plan.temp.matchers.ReferenceMatchers.anyRef) List(java.util.List) BindingMatcher(com.apple.foundationdb.record.query.plan.temp.matchers.BindingMatcher) ImmutableList(com.google.common.collect.ImmutableList) API(com.apple.foundationdb.annotation.API) QuantifierMatchers.forEachQuantifierOverRef(com.apple.foundationdb.record.query.plan.temp.matchers.QuantifierMatchers.forEachQuantifierOverRef) ExpressionRef(com.apple.foundationdb.record.query.plan.temp.ExpressionRef) ListMatcher.exactly(com.apple.foundationdb.record.query.plan.temp.matchers.ListMatcher.exactly) QuantifierMatchers.forEachQuantifier(com.apple.foundationdb.record.query.plan.temp.matchers.QuantifierMatchers.forEachQuantifier) Nonnull(javax.annotation.Nonnull) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) LogicalFilterExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalFilterExpression) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) QuantifierMatchers.forEachQuantifier(com.apple.foundationdb.record.query.plan.temp.matchers.QuantifierMatchers.forEachQuantifier)

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