Search in sources :

Example 1 with UnionExecutionPlan

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

the class Union method build.

@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> hints, ProjectionBuilder projectionBuilder, int limit, int offset, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
    Integer childPageSizeHint = limit != TopN.NO_LIMIT ? limitAndOffset(limit, offset) : null;
    ExecutionPlan left = lhs.build(plannerContext, hints, projectionBuilder, limit + offset, TopN.NO_OFFSET, null, childPageSizeHint, params, subQueryResults);
    ExecutionPlan right = rhs.build(plannerContext, hints, projectionBuilder, limit + offset, TopN.NO_OFFSET, null, childPageSizeHint, params, subQueryResults);
    addCastsForIncompatibleObjects(right);
    if (left.resultDescription().hasRemainingLimitOrOffset()) {
        left = Merge.ensureOnHandler(left, plannerContext);
    }
    if (right.resultDescription().hasRemainingLimitOrOffset()) {
        right = Merge.ensureOnHandler(right, plannerContext);
    }
    ResultDescription leftResultDesc = left.resultDescription();
    ResultDescription rightResultDesc = right.resultDescription();
    assert DataTypes.isCompatibleType(leftResultDesc.streamOutputs(), rightResultDesc.streamOutputs()) : "Left and right must output the same types, got " + "lhs=" + leftResultDesc.streamOutputs() + ", rhs=" + rightResultDesc.streamOutputs();
    MergePhase mergePhase = new MergePhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "union", leftResultDesc.nodeIds().size() + rightResultDesc.nodeIds().size(), 2, Collections.singletonList(plannerContext.handlerNode()), leftResultDesc.streamOutputs(), Collections.emptyList(), DistributionInfo.DEFAULT_BROADCAST, leftResultDesc.orderBy());
    return new UnionExecutionPlan(left, right, mergePhase, limit, offset, lhs.outputs().size(), TopN.NO_LIMIT, leftResultDesc.orderBy());
}
Also used : UnionExecutionPlan(io.crate.planner.UnionExecutionPlan) ExecutionPlan(io.crate.planner.ExecutionPlan) MergePhase(io.crate.execution.dsl.phases.MergePhase) UnionExecutionPlan(io.crate.planner.UnionExecutionPlan) ResultDescription(io.crate.planner.ResultDescription)

Aggregations

MergePhase (io.crate.execution.dsl.phases.MergePhase)1 ExecutionPlan (io.crate.planner.ExecutionPlan)1 ResultDescription (io.crate.planner.ResultDescription)1 UnionExecutionPlan (io.crate.planner.UnionExecutionPlan)1