use of com.apple.foundationdb.record.query.plan.temp.expressions.LogicalProjectionExpression in project fdb-record-layer by FoundationDB.
the class RelationalExpression method fromRecordQuery.
@Nonnull
static RelationalExpression fromRecordQuery(@Nonnull PlanContext context, @Nonnull RecordQuery query) {
query.validate(context.getMetaData());
Quantifier.ForEach quantifier = Quantifier.forEach(GroupExpressionRef.of(new FullUnorderedScanExpression(context.getMetaData().getRecordTypes().keySet())));
if (!context.getRecordTypes().isEmpty()) {
quantifier = Quantifier.forEach(GroupExpressionRef.of(new LogicalTypeFilterExpression(new HashSet<>(context.getRecordTypes()), quantifier)));
}
final SelectExpression selectExpression;
if (query.getFilter() != null) {
selectExpression = query.getFilter().expand(quantifier.getAlias()).buildSelectWithBase(quantifier);
} else {
selectExpression = GraphExpansion.empty().buildSelectWithBase(quantifier);
}
quantifier = Quantifier.forEach(GroupExpressionRef.of(selectExpression));
if (query.removesDuplicates()) {
quantifier = Quantifier.forEach(GroupExpressionRef.of(new LogicalDistinctExpression(quantifier)));
}
if (query.getSort() != null) {
quantifier = Quantifier.forEach(GroupExpressionRef.of(new LogicalSortExpression(query.getSort(), query.isSortReverse(), quantifier)));
} else {
quantifier = Quantifier.forEach(GroupExpressionRef.of(new LogicalSortExpression(null, false, quantifier)));
}
if (query.getRequiredResults() != null) {
final List<? extends Value> projectedValues = Value.fromKeyExpressions(query.getRequiredResults().stream().flatMap(keyExpression -> keyExpression.normalizeKeyForPositions().stream()).collect(ImmutableList.toImmutableList()), quantifier.getAlias());
quantifier = Quantifier.forEach(GroupExpressionRef.of(new LogicalProjectionExpression(projectedValues, quantifier)));
}
return quantifier.getRangesOver().get();
}
use of com.apple.foundationdb.record.query.plan.temp.expressions.LogicalProjectionExpression in project fdb-record-layer by FoundationDB.
the class MergeProjectionAndFetchRule method onMatch.
@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
final LogicalProjectionExpression projectionExpression = call.get(root);
// if the fetch is able to push all values we can eliminate the fetch as well
final RecordQueryFetchFromPartialRecordPlan fetchPlan = call.get(innerPlanMatcher);
final CorrelationIdentifier newInnerAlias = CorrelationIdentifier.uniqueID();
final List<? extends Value> resultValues = projectionExpression.getResultValues();
final boolean allPushable = resultValues.stream().allMatch(value -> fetchPlan.pushValue(value, newInnerAlias).isPresent());
if (allPushable) {
// all fields in the projection are already available underneath the fetch
// we don't need the projection nor the fetch
call.yield(call.ref(fetchPlan.getChild()));
}
}
Aggregations