Search in sources :

Example 11 with SelectExpression

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

the class ValueIndexLikeExpansionVisitor method visitExpression.

@Nonnull
@Override
public GraphExpansion visitExpression(@Nonnull final NestingKeyExpression nestingKeyExpression) {
    final VisitorState state = getCurrentState();
    final List<String> fieldNamePrefix = state.getFieldNamePrefix();
    final CorrelationIdentifier baseAlias = state.getBaseAlias();
    final FieldKeyExpression parent = nestingKeyExpression.getParent();
    final KeyExpression child = nestingKeyExpression.getChild();
    switch(parent.getFanType()) {
        case None:
            List<String> newPrefix = ImmutableList.<String>builder().addAll(fieldNamePrefix).add(parent.getFieldName()).build();
            return pop(child.expand(push(state.withFieldNamePrefix(newPrefix))));
        case FanOut:
            // explode the parent field(s) also depending on the prefix
            final Quantifier childBase = parent.explodeField(baseAlias, fieldNamePrefix);
            // expand the children of the key expression and then unify them into an expansion of this expression
            final GraphExpansion.Sealed sealedChildExpansion = pop(child.expand(push(state.withBaseAlias(childBase.getAlias()).withFieldNamePrefix(ImmutableList.of())))).seal();
            final SelectExpression selectExpression = sealedChildExpansion.buildSelectWithBase(childBase);
            final Quantifier childQuantifier = Quantifier.forEach(GroupExpressionRef.of(selectExpression));
            return sealedChildExpansion.derivedWithQuantifier(childQuantifier);
        case Concatenate:
        default:
            throw new RecordCoreException("unsupported fan type");
    }
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) FieldKeyExpression(com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression) VisitorState(com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) FieldKeyExpression(com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression) NestingKeyExpression(com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression) ThenKeyExpression(com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression) EmptyKeyExpression(com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) Nonnull(javax.annotation.Nonnull)

Example 12 with SelectExpression

use of com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression 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

SelectExpression (com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)12 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)7 Nonnull (javax.annotation.Nonnull)7 ImmutableList (com.google.common.collect.ImmutableList)5 API (com.apple.foundationdb.annotation.API)4 GroupExpressionRef (com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef)4 BindingMatcher (com.apple.foundationdb.record.query.plan.temp.matchers.BindingMatcher)4 PlannerBindings (com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings)4 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)3 PlannerRule (com.apple.foundationdb.record.query.plan.temp.PlannerRule)3 PlannerRuleCall (com.apple.foundationdb.record.query.plan.temp.PlannerRuleCall)3 ExplodeExpression (com.apple.foundationdb.record.query.plan.temp.expressions.ExplodeExpression)3 CollectionMatcher (com.apple.foundationdb.record.query.plan.temp.matchers.CollectionMatcher)3 MultiMatcher.some (com.apple.foundationdb.record.query.plan.temp.matchers.MultiMatcher.some)3 QuantifierMatchers.forEachQuantifier (com.apple.foundationdb.record.query.plan.temp.matchers.QuantifierMatchers.forEachQuantifier)3 LiteralValue (com.apple.foundationdb.record.query.predicates.LiteralValue)3 QuantifiedColumnValue (com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue)3 QueryPredicate (com.apple.foundationdb.record.query.predicates.QueryPredicate)3 Value (com.apple.foundationdb.record.query.predicates.Value)3 CORRELATION (com.apple.foundationdb.record.Bindings.Internal.CORRELATION)2