Search in sources :

Example 1 with FullUnorderedScanExpression

use of com.apple.foundationdb.record.query.plan.temp.expressions.FullUnorderedScanExpression 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();
}
Also used : LogicalTypeFilterExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalTypeFilterExpression) LogicalProjectionExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalProjectionExpression) FullUnorderedScanExpression(com.apple.foundationdb.record.query.plan.temp.expressions.FullUnorderedScanExpression) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) LogicalDistinctExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalDistinctExpression) HashSet(java.util.HashSet) LogicalSortExpression(com.apple.foundationdb.record.query.plan.temp.expressions.LogicalSortExpression) Nonnull(javax.annotation.Nonnull)

Example 2 with FullUnorderedScanExpression

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

the class FullUnorderedExpressionToScanPlanRule method onMatch.

@Override
public void onMatch(@Nonnull PlannerRuleCall call) {
    final FullUnorderedScanExpression fullUnorderedScanExpression = call.get(root);
    call.yield(call.ref(new RecordQueryScanPlan(fullUnorderedScanExpression.getRecordTypes(), ScanComparisons.EMPTY, false)));
}
Also used : RecordQueryScanPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan) FullUnorderedScanExpression(com.apple.foundationdb.record.query.plan.temp.expressions.FullUnorderedScanExpression)

Aggregations

FullUnorderedScanExpression (com.apple.foundationdb.record.query.plan.temp.expressions.FullUnorderedScanExpression)2 RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)1 LogicalDistinctExpression (com.apple.foundationdb.record.query.plan.temp.expressions.LogicalDistinctExpression)1 LogicalProjectionExpression (com.apple.foundationdb.record.query.plan.temp.expressions.LogicalProjectionExpression)1 LogicalSortExpression (com.apple.foundationdb.record.query.plan.temp.expressions.LogicalSortExpression)1 LogicalTypeFilterExpression (com.apple.foundationdb.record.query.plan.temp.expressions.LogicalTypeFilterExpression)1 SelectExpression (com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)1 HashSet (java.util.HashSet)1 Nonnull (javax.annotation.Nonnull)1