use of io.crate.execution.dsl.projection.TopNDistinctProjection in project crate by crate.
the class TopNDistinct method build.
@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> planHints, ProjectionBuilder projectionBuilder, int limitHint, int offsetHint, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
var executionPlan = source.build(plannerContext, planHints, projectionBuilder, TopN.NO_LIMIT, TopN.NO_OFFSET, null, null, params, subQueryResults);
if (executionPlan.resultDescription().hasRemainingLimitOrOffset()) {
executionPlan = Merge.ensureOnHandler(executionPlan, plannerContext);
}
if (!source.outputs().equals(outputs)) {
EvalProjection evalProjection = new EvalProjection(InputColumns.create(outputs, new InputColumns.SourceSymbols(source.outputs())));
executionPlan.addProjection(evalProjection);
}
int limit = DataTypes.INTEGER.sanitizeValue(evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), this.limit, params, subQueryResults));
int offset = DataTypes.INTEGER.sanitizeValue(evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), this.offset, params, subQueryResults));
var inputColOutputs = InputColumn.mapToInputColumns(outputs);
executionPlan.addProjection(new TopNDistinctProjection(limit + offset, inputColOutputs, source.preferShardProjections() ? RowGranularity.SHARD : RowGranularity.CLUSTER));
boolean onHandler = ExecutionPhases.executesOnHandler(plannerContext.handlerNode(), executionPlan.resultDescription().nodeIds());
if (!onHandler || source.preferShardProjections()) {
if (!onHandler) {
executionPlan = Merge.ensureOnHandler(executionPlan, plannerContext);
}
TopNDistinctProjection topNDistinct = new TopNDistinctProjection(limit + offset, inputColOutputs, RowGranularity.CLUSTER);
executionPlan.addProjection(topNDistinct);
}
if (offset > 0) {
// TopNDistinctProjection outputs a distinct result-set,
// That allows us to use the TopNProjection to apply the offset
executionPlan.addProjection(new TopNProjection(limit, offset, Symbols.typeView(inputColOutputs)));
}
return executionPlan;
}
Aggregations