Search in sources :

Example 1 with VisitorState

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

the class ValueIndexLikeExpansionVisitor method visitExpression.

@Nonnull
@Override
public GraphExpansion visitExpression(@Nonnull FieldKeyExpression fieldKeyExpression) {
    final String fieldName = fieldKeyExpression.getFieldName();
    final KeyExpression.FanType fanType = fieldKeyExpression.getFanType();
    final VisitorState state = getCurrentState();
    final List<String> fieldNamePrefix = state.getFieldNamePrefix();
    final CorrelationIdentifier baseAlias = state.getBaseAlias();
    final List<String> fieldNames = ImmutableList.<String>builder().addAll(fieldNamePrefix).add(fieldName).build();
    final Value value;
    final Placeholder predicate;
    switch(fanType) {
        case FanOut:
            // explode this field and prefixes of this field
            final Quantifier childBase = fieldKeyExpression.explodeField(baseAlias, fieldNamePrefix);
            value = state.registerValue(QuantifiedObjectValue.of(childBase.getAlias()));
            final GraphExpansion childExpansion;
            if (state.isKey()) {
                predicate = value.asPlaceholder(newParameterAlias());
                childExpansion = GraphExpansion.ofPlaceholder(value, predicate);
            } else {
                childExpansion = GraphExpansion.ofResultValue(value);
            }
            final SelectExpression selectExpression = childExpansion.buildSelectWithBase(childBase);
            final Quantifier childQuantifier = Quantifier.forEach(GroupExpressionRef.of(selectExpression));
            final GraphExpansion.Sealed sealedChildExpansion = childExpansion.seal();
            return sealedChildExpansion.derivedWithQuantifier(childQuantifier);
        case None:
            value = state.registerValue(new FieldValue(QuantifiedColumnValue.of(baseAlias, 0), fieldNames));
            if (state.isKey()) {
                predicate = value.asPlaceholder(newParameterAlias());
                return GraphExpansion.ofPlaceholder(value, predicate);
            }
            return GraphExpansion.ofResultValue(value);
        // TODO collect/concatenate function
        case Concatenate:
        default:
    }
    throw new UnsupportedOperationException();
}
Also used : Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) 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) VisitorState(com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState) QuantifiedObjectValue(com.apple.foundationdb.record.query.predicates.QuantifiedObjectValue) Value(com.apple.foundationdb.record.query.predicates.Value) EmptyValue(com.apple.foundationdb.record.query.predicates.EmptyValue) KeyExpressionWithValue(com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithValue) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) QuantifiedColumnValue(com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) Nonnull(javax.annotation.Nonnull)

Example 2 with VisitorState

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

the class ValueIndexLikeExpansionVisitor method visitExpression.

@Nonnull
@Override
public GraphExpansion visitExpression(@Nonnull final ThenKeyExpression thenKeyExpression) {
    final ImmutableList.Builder<GraphExpansion> expandedPredicatesBuilder = ImmutableList.builder();
    final VisitorState state = getCurrentState();
    int currentOrdinal = state.getCurrentOrdinal();
    for (KeyExpression child : thenKeyExpression.getChildren()) {
        final GraphExpansion graphExpansion = pop(child.expand(push(state.withCurrentOrdinal(currentOrdinal))));
        currentOrdinal += graphExpansion.getResultValues().size();
        expandedPredicatesBuilder.add(graphExpansion);
    }
    return GraphExpansion.ofOthers(expandedPredicatesBuilder.build());
}
Also used : VisitorState(com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState) ImmutableList(com.google.common.collect.ImmutableList) 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) Nonnull(javax.annotation.Nonnull)

Example 3 with VisitorState

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

the class ValueIndexLikeExpansionVisitor method visitExpression.

@Nonnull
@Override
public GraphExpansion visitExpression(@Nonnull final KeyExpressionWithValue keyExpressionWithValue) {
    final VisitorState state = getCurrentState();
    final Value value = state.registerValue(keyExpressionWithValue.toValue(state.getBaseAlias(), state.getFieldNamePrefix()));
    if (state.isKey()) {
        final Placeholder predicate = value.asPlaceholder(newParameterAlias());
        return GraphExpansion.ofPlaceholder(value, predicate);
    }
    return GraphExpansion.ofResultValue(value);
}
Also used : Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) VisitorState(com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState) QuantifiedObjectValue(com.apple.foundationdb.record.query.predicates.QuantifiedObjectValue) Value(com.apple.foundationdb.record.query.predicates.Value) EmptyValue(com.apple.foundationdb.record.query.predicates.EmptyValue) KeyExpressionWithValue(com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithValue) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) QuantifiedColumnValue(com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue) Nonnull(javax.annotation.Nonnull)

Example 4 with VisitorState

use of com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState 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)

Aggregations

VisitorState (com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState)4 Nonnull (javax.annotation.Nonnull)4 EmptyKeyExpression (com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression)3 FieldKeyExpression (com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression)3 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)3 NestingKeyExpression (com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression)3 ThenKeyExpression (com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression)3 KeyExpressionWithValue (com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithValue)2 SelectExpression (com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)2 EmptyValue (com.apple.foundationdb.record.query.predicates.EmptyValue)2 FieldValue (com.apple.foundationdb.record.query.predicates.FieldValue)2 QuantifiedColumnValue (com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue)2 QuantifiedObjectValue (com.apple.foundationdb.record.query.predicates.QuantifiedObjectValue)2 Value (com.apple.foundationdb.record.query.predicates.Value)2 Placeholder (com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder)2 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)1 ImmutableList (com.google.common.collect.ImmutableList)1