Search in sources :

Example 1 with BooleanPredicateNormalizer

use of com.apple.foundationdb.record.query.plan.planning.BooleanPredicateNormalizer in project fdb-record-layer by FoundationDB.

the class NormalizePredicatesRule method onMatch.

@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
    final PlannerBindings bindings = call.getBindings();
    final SelectExpression selectExpression = bindings.get(root);
    final Collection<? extends QueryPredicate> predicates = bindings.get(predicatesMatcher);
    final Collection<? extends Quantifier> quantifiers = bindings.get(innerQuantifiersMatcher);
    // create one big conjuncted predicate
    final QueryPredicate conjunctedPredicate = AndPredicate.and(predicates);
    final BooleanPredicateNormalizer cnfNormalizer = BooleanPredicateNormalizer.forConfiguration(BooleanPredicateNormalizer.Mode.CNF, call.getContext().getPlannerConfiguration());
    cnfNormalizer.normalize(conjunctedPredicate, false).ifPresent(cnfPredicate -> call.yield(call.ref(new SelectExpression(selectExpression.getResultValues(), quantifiers.stream().map(quantifier -> quantifier.toBuilder().build(quantifier.getRangesOver())).collect(ImmutableList.toImmutableList()), AndPredicate.conjuncts(cnfPredicate)))));
    final BooleanPredicateNormalizer dnfNormalizer = BooleanPredicateNormalizer.forConfiguration(BooleanPredicateNormalizer.Mode.DNF, call.getContext().getPlannerConfiguration());
    dnfNormalizer.normalize(conjunctedPredicate, false).ifPresent(dnfPredicate -> call.yield(call.ref(new SelectExpression(selectExpression.getResultValues(), quantifiers.stream().map(quantifier -> quantifier.toBuilder().build(quantifier.getRangesOver())).collect(ImmutableList.toImmutableList()), ImmutableList.of(dnfPredicate)))));
}
Also used : PlannerRuleCall(com.apple.foundationdb.record.query.plan.temp.PlannerRuleCall) RelationalExpressionMatchers(com.apple.foundationdb.record.query.plan.temp.matchers.RelationalExpressionMatchers) PlannerRule(com.apple.foundationdb.record.query.plan.temp.PlannerRule) QueryPredicateMatchers.anyPredicate(com.apple.foundationdb.record.query.plan.temp.matchers.QueryPredicateMatchers.anyPredicate) Collection(java.util.Collection) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) MultiMatcher.all(com.apple.foundationdb.record.query.plan.temp.matchers.MultiMatcher.all) BooleanPredicateNormalizer(com.apple.foundationdb.record.query.plan.planning.BooleanPredicateNormalizer) CollectionMatcher(com.apple.foundationdb.record.query.plan.temp.matchers.CollectionMatcher) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) AndPredicate(com.apple.foundationdb.record.query.predicates.AndPredicate) BindingMatcher(com.apple.foundationdb.record.query.plan.temp.matchers.BindingMatcher) ImmutableList(com.google.common.collect.ImmutableList) API(com.apple.foundationdb.annotation.API) QuantifierMatchers.anyQuantifier(com.apple.foundationdb.record.query.plan.temp.matchers.QuantifierMatchers.anyQuantifier) Nonnull(javax.annotation.Nonnull) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) PlannerBindings(com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings) BooleanPredicateNormalizer(com.apple.foundationdb.record.query.plan.planning.BooleanPredicateNormalizer) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)

Aggregations

API (com.apple.foundationdb.annotation.API)1 BooleanPredicateNormalizer (com.apple.foundationdb.record.query.plan.planning.BooleanPredicateNormalizer)1 PlannerRule (com.apple.foundationdb.record.query.plan.temp.PlannerRule)1 PlannerRuleCall (com.apple.foundationdb.record.query.plan.temp.PlannerRuleCall)1 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)1 SelectExpression (com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)1 BindingMatcher (com.apple.foundationdb.record.query.plan.temp.matchers.BindingMatcher)1 CollectionMatcher (com.apple.foundationdb.record.query.plan.temp.matchers.CollectionMatcher)1 MultiMatcher.all (com.apple.foundationdb.record.query.plan.temp.matchers.MultiMatcher.all)1 PlannerBindings (com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings)1 QuantifierMatchers.anyQuantifier (com.apple.foundationdb.record.query.plan.temp.matchers.QuantifierMatchers.anyQuantifier)1 QueryPredicateMatchers.anyPredicate (com.apple.foundationdb.record.query.plan.temp.matchers.QueryPredicateMatchers.anyPredicate)1 RelationalExpressionMatchers (com.apple.foundationdb.record.query.plan.temp.matchers.RelationalExpressionMatchers)1 AndPredicate (com.apple.foundationdb.record.query.predicates.AndPredicate)1 QueryPredicate (com.apple.foundationdb.record.query.predicates.QueryPredicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 Nonnull (javax.annotation.Nonnull)1