use of io.crate.action.sql.RowConsumerToResultReceiver 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);
}
}
}
Aggregations