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");
}
}
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)))));
}
Aggregations