Search in sources :

Example 6 with PositionalOrderBy

use of io.crate.planner.PositionalOrderBy in project crate by crate.

the class Order method build.

@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> planHints, ProjectionBuilder projectionBuilder, int limit, int offset, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
    ExecutionPlan plan = source.build(plannerContext, planHints, projectionBuilder, limit, offset, orderBy, pageSizeHint, params, subQueryResults);
    if (plan.resultDescription().orderBy() != null) {
        // Collect applied ORDER BY eagerly to produce a optimized execution plan;
        if (source instanceof Collect) {
            return plan;
        }
    }
    if (plan.resultDescription().hasRemainingLimitOrOffset()) {
        plan = Merge.ensureOnHandler(plan, plannerContext);
    }
    InputColumns.SourceSymbols ctx = new InputColumns.SourceSymbols(source.outputs());
    List<Symbol> orderByInputColumns = InputColumns.create(this.orderBy.orderBySymbols(), ctx);
    ensureOrderByColumnsArePresentInOutputs(orderByInputColumns);
    OrderedTopNProjection topNProjection = new OrderedTopNProjection(Limit.limitAndOffset(limit, offset), 0, InputColumns.create(outputs, ctx), orderByInputColumns, this.orderBy.reverseFlags(), this.orderBy.nullsFirst());
    PositionalOrderBy positionalOrderBy = PositionalOrderBy.of(this.orderBy, outputs);
    plan.addProjection(topNProjection, limit, offset, positionalOrderBy);
    return plan;
}
Also used : InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) PositionalOrderBy(io.crate.planner.PositionalOrderBy) ExecutionPlan(io.crate.planner.ExecutionPlan) Symbol(io.crate.expression.symbol.Symbol) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection)

Aggregations

PositionalOrderBy (io.crate.planner.PositionalOrderBy)6 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)3 Symbol (io.crate.expression.symbol.Symbol)3 Test (org.junit.Test)3 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)2 MergePhase (io.crate.execution.dsl.phases.MergePhase)2 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)2 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)2 InputColumns (io.crate.execution.dsl.projection.builder.InputColumns)2 ExecutionPlan (io.crate.planner.ExecutionPlan)2 Merge (io.crate.planner.Merge)2 Collect (io.crate.planner.node.dql.Collect)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 OrderBy (io.crate.analyze.OrderBy)1 DocTableRelation (io.crate.analyze.relations.DocTableRelation)1 RowAccountingWithEstimatorsTest (io.crate.breaker.RowAccountingWithEstimatorsTest)1 Row (io.crate.data.Row)1 NestedLoopPhase (io.crate.execution.dsl.phases.NestedLoopPhase)1 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)1 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)1