use of io.crate.planner.ExecutionPlan in project crate by crate.
the class ProjectSet 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 sourcePlan = source.build(plannerContext, planHints, projectionBuilder, limit, offset, order, pageSizeHint, params, subQueryResults);
InputColumns.SourceSymbols sourceSymbols = new InputColumns.SourceSymbols(source.outputs());
List<Symbol> tableFunctionsWithInputs = InputColumns.create(this.tableFunctions, sourceSymbols);
List<Symbol> standaloneWithInputs = InputColumns.create(this.standalone, sourceSymbols);
sourcePlan.addProjection(new ProjectSetProjection(tableFunctionsWithInputs, standaloneWithInputs));
return sourcePlan;
}
use of io.crate.planner.ExecutionPlan in project crate by crate.
the class WindowAgg 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) {
InputColumns.SourceSymbols sourceSymbols = new InputColumns.SourceSymbols(source.outputs());
SubQueryAndParamBinder binder = new SubQueryAndParamBinder(params, subQueryResults);
Function<Symbol, Symbol> toInputCols = binder.andThen(s -> InputColumns.create(s, sourceSymbols));
List<WindowFunction> boundWindowFunctions = (List<WindowFunction>) (List) Lists2.map(windowFunctions, toInputCols);
List<Projection> projections = new ArrayList<>();
WindowAggProjection windowAggProjection = new WindowAggProjection(windowDefinition.map(toInputCols), boundWindowFunctions, InputColumns.create(this.standalone, sourceSymbols));
projections.add(windowAggProjection);
ExecutionPlan sourcePlan = source.build(plannerContext, planHints, projectionBuilder, TopN.NO_LIMIT, TopN.NO_OFFSET, null, pageSizeHint, params, subQueryResults);
ResultDescription resultDescription = sourcePlan.resultDescription();
boolean executesOnHandler = executesOnHandler(plannerContext.handlerNode(), resultDescription.nodeIds());
boolean nonDistExecution = windowDefinition.partitions().isEmpty() || resultDescription.hasRemainingLimitOrOffset() || executesOnHandler;
if (nonDistExecution) {
sourcePlan = Merge.ensureOnHandler(sourcePlan, plannerContext);
for (Projection projection : projections) {
sourcePlan.addProjection(projection);
}
} else {
sourcePlan.setDistributionInfo(new DistributionInfo(DistributionType.MODULO, source.outputs().indexOf(windowDefinition.partitions().iterator().next())));
MergePhase distWindowAgg = new MergePhase(UUIDs.dirtyUUID(), plannerContext.nextExecutionPhaseId(), "distWindowAgg", resultDescription.nodeIds().size(), resultDescription.numOutputs(), resultDescription.nodeIds(), resultDescription.streamOutputs(), projections, DistributionInfo.DEFAULT_BROADCAST, null);
return new Merge(sourcePlan, distWindowAgg, TopN.NO_LIMIT, TopN.NO_OFFSET, windowAggProjection.outputs().size(), resultDescription.maxRowsPerNode(), null);
}
return sourcePlan;
}
use of io.crate.planner.ExecutionPlan in project crate by crate.
the class CopyToPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
ExecutionPlan executionPlan = planCopyToExecution(copyTo, plannerContext, tableStats, executor.projectionBuilder(), params, subQueryResults);
NodeOperationTree nodeOpTree = NodeOperationTreeGenerator.fromPlan(executionPlan, executor.localNodeId());
executor.phasesTaskFactory().create(plannerContext.jobId(), List.of(nodeOpTree)).execute(consumer, plannerContext.transactionContext());
}
use of io.crate.planner.ExecutionPlan in project crate by crate.
the class CopyToPlan method planCopyToExecution.
@VisibleForTesting
static ExecutionPlan planCopyToExecution(AnalyzedCopyTo copyTo, PlannerContext context, TableStats tableStats, ProjectionBuilder projectionBuilder, Row params, SubQueryResults subQueryResults) {
var boundedCopyTo = bind(copyTo, context.transactionContext(), context.nodeContext(), params, subQueryResults);
WriterProjection.OutputFormat outputFormat = boundedCopyTo.outputFormat();
if (outputFormat == null) {
outputFormat = boundedCopyTo.columnsDefined() ? WriterProjection.OutputFormat.JSON_ARRAY : WriterProjection.OutputFormat.JSON_OBJECT;
}
WriterProjection projection = ProjectionBuilder.writerProjection(boundedCopyTo.outputs(), boundedCopyTo.uri(), boundedCopyTo.compressionType(), boundedCopyTo.overwrites(), boundedCopyTo.outputNames(), outputFormat, boundedCopyTo.withClauseOptions());
LogicalPlan collect = Collect.create(new DocTableRelation(boundedCopyTo.table()), boundedCopyTo.outputs(), boundedCopyTo.whereClause(), tableStats, context.params());
LogicalPlan source = optimizeCollect(context, tableStats, collect);
ExecutionPlan executionPlan = source.build(context, Set.of(), projectionBuilder, 0, 0, null, null, params, SubQueryResults.EMPTY);
executionPlan.addProjection(projection);
return Merge.ensureOnHandler(executionPlan, context, List.of(MergeCountProjection.INSTANCE));
}
use of io.crate.planner.ExecutionPlan in project crate by crate.
the class CopyFromPlan method executeOrFail.
@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
ExecutionPlan plan = planCopyFromExecution(copyFrom, dependencies.clusterService().state().nodes(), plannerContext, params, subQueryResults);
NodeOperationTree nodeOpTree = NodeOperationTreeGenerator.fromPlan(plan, dependencies.localNodeId());
dependencies.phasesTaskFactory().create(plannerContext.jobId(), List.of(nodeOpTree)).execute(consumer, plannerContext.transactionContext());
}
Aggregations