Search in sources :

Example 6 with ExecutionPlan

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;
}
Also used : ProjectSetProjection(io.crate.execution.dsl.projection.ProjectSetProjection) InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) ExecutionPlan(io.crate.planner.ExecutionPlan) Symbol(io.crate.expression.symbol.Symbol)

Example 7 with ExecutionPlan

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;
}
Also used : InputColumns(io.crate.execution.dsl.projection.builder.InputColumns) Symbol(io.crate.expression.symbol.Symbol) ArrayList(java.util.ArrayList) Projection(io.crate.execution.dsl.projection.Projection) WindowAggProjection(io.crate.execution.dsl.projection.WindowAggProjection) DistributionInfo(io.crate.planner.distribution.DistributionInfo) WindowFunction(io.crate.expression.symbol.WindowFunction) ExecutionPlan(io.crate.planner.ExecutionPlan) MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) ResultDescription(io.crate.planner.ResultDescription) WindowAggProjection(io.crate.execution.dsl.projection.WindowAggProjection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with ExecutionPlan

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());
}
Also used : NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) ExecutionPlan(io.crate.planner.ExecutionPlan)

Example 9 with ExecutionPlan

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));
}
Also used : WriterProjection(io.crate.execution.dsl.projection.WriterProjection) ExecutionPlan(io.crate.planner.ExecutionPlan) DocTableRelation(io.crate.analyze.relations.DocTableRelation) LogicalPlan(io.crate.planner.operators.LogicalPlan) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 10 with ExecutionPlan

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());
}
Also used : NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) ExecutionPlan(io.crate.planner.ExecutionPlan)

Aggregations

ExecutionPlan (io.crate.planner.ExecutionPlan)19 Symbol (io.crate.expression.symbol.Symbol)8 MergePhase (io.crate.execution.dsl.phases.MergePhase)4 ResultDescription (io.crate.planner.ResultDescription)4 List (java.util.List)4 DocTableRelation (io.crate.analyze.relations.DocTableRelation)3 NodeOperationTree (io.crate.execution.dsl.phases.NodeOperationTree)3 InputColumns (io.crate.execution.dsl.projection.builder.InputColumns)3 SelectSymbol (io.crate.expression.symbol.SelectSymbol)3 Merge (io.crate.planner.Merge)3 Collect (io.crate.planner.node.dql.Collect)3 ArrayList (java.util.ArrayList)3 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)2 Projection (io.crate.execution.dsl.projection.Projection)2 ProjectionBuilder (io.crate.execution.dsl.projection.builder.ProjectionBuilder)2 PartitionName (io.crate.metadata.PartitionName)2 RelationName (io.crate.metadata.RelationName)2 Join (io.crate.planner.node.dql.join.Join)2 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 Collection (java.util.Collection)2