Search in sources :

Example 1 with CopyFromPlan

use of io.crate.planner.statement.CopyFromPlan in project crate by crate.

the class ExplainPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    if (context != null) {
        assert subPlan instanceof LogicalPlan : "subPlan must be a LogicalPlan";
        LogicalPlan plan = (LogicalPlan) subPlan;
        /**
         * EXPLAIN ANALYZE does not support analyzing {@link io.crate.planner.MultiPhasePlan}s
         */
        if (plan.dependencies().isEmpty()) {
            UUID jobId = plannerContext.jobId();
            BaseResultReceiver resultReceiver = new BaseResultReceiver();
            RowConsumer noopRowConsumer = new RowConsumerToResultReceiver(resultReceiver, 0, t -> {
            });
            Timer timer = context.createTimer(Phase.Execute.name());
            timer.start();
            NodeOperationTree operationTree = LogicalPlanner.getNodeOperationTree(plan, dependencies, plannerContext, params, subQueryResults);
            resultReceiver.completionFuture().whenComplete(createResultConsumer(dependencies, consumer, jobId, timer, operationTree));
            LogicalPlanner.executeNodeOpTree(dependencies, plannerContext.transactionContext(), jobId, noopRowConsumer, true, operationTree);
        } else {
            consumer.accept(null, new UnsupportedOperationException("EXPLAIN ANALYZE does not support profiling multi-phase plans, " + "such as queries with scalar subselects."));
        }
    } else {
        if (subPlan instanceof LogicalPlan) {
            PrintContext printContext = new PrintContext();
            ((LogicalPlan) subPlan).print(printContext);
            consumer.accept(InMemoryBatchIterator.of(new Row1(printContext.toString()), SENTINEL), null);
        } else if (subPlan instanceof CopyFromPlan) {
            ExecutionPlan executionPlan = CopyFromPlan.planCopyFromExecution(((CopyFromPlan) subPlan).copyFrom(), dependencies.clusterService().state().nodes(), plannerContext, params, subQueryResults);
            String planAsJson = DataTypes.STRING.implicitCast(PlanPrinter.objectMap(executionPlan));
            consumer.accept(InMemoryBatchIterator.of(new Row1(planAsJson), SENTINEL), null);
        } else {
            consumer.accept(InMemoryBatchIterator.of(new Row1("EXPLAIN not supported for " + subPlan.getClass().getSimpleName()), SENTINEL), null);
        }
    }
}
Also used : CopyFromPlan(io.crate.planner.statement.CopyFromPlan) Row1(io.crate.data.Row1) RowConsumerToResultReceiver(io.crate.action.sql.RowConsumerToResultReceiver) NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) ExecutionPlan(io.crate.planner.ExecutionPlan) Timer(io.crate.profile.Timer) PrintContext(io.crate.planner.operators.PrintContext) BaseResultReceiver(io.crate.action.sql.BaseResultReceiver) LogicalPlan(io.crate.planner.operators.LogicalPlan) RowConsumer(io.crate.data.RowConsumer) UUID(java.util.UUID)

Aggregations

BaseResultReceiver (io.crate.action.sql.BaseResultReceiver)1 RowConsumerToResultReceiver (io.crate.action.sql.RowConsumerToResultReceiver)1 Row1 (io.crate.data.Row1)1 RowConsumer (io.crate.data.RowConsumer)1 NodeOperationTree (io.crate.execution.dsl.phases.NodeOperationTree)1 ExecutionPlan (io.crate.planner.ExecutionPlan)1 LogicalPlan (io.crate.planner.operators.LogicalPlan)1 PrintContext (io.crate.planner.operators.PrintContext)1 CopyFromPlan (io.crate.planner.statement.CopyFromPlan)1 Timer (io.crate.profile.Timer)1 UUID (java.util.UUID)1