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