use of io.crate.execution.dsl.phases.NodeOperationTree 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.execution.dsl.phases.NodeOperationTree 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());
}
use of io.crate.execution.dsl.phases.NodeOperationTree in project crate by crate.
the class JobLauncher method executeBulk.
public List<CompletableFuture<Long>> executeBulk(TransactionContext txnCtx) {
Iterable<NodeOperation> nodeOperations = nodeOperationTrees.stream().flatMap(opTree -> opTree.nodeOperations().stream())::iterator;
Map<String, Collection<NodeOperation>> operationByServer = NodeOperationGrouper.groupByServer(nodeOperations);
List<ExecutionPhase> handlerPhases = new ArrayList<>(nodeOperationTrees.size());
List<RowConsumer> handlerConsumers = new ArrayList<>(nodeOperationTrees.size());
List<CompletableFuture<Long>> results = new ArrayList<>(nodeOperationTrees.size());
for (NodeOperationTree nodeOperationTree : nodeOperationTrees) {
CollectingRowConsumer<?, Long> consumer = new CollectingRowConsumer<>(Collectors.collectingAndThen(Collectors.summingLong(r -> ((long) r.get(0))), sum -> sum));
handlerConsumers.add(consumer);
results.add(consumer.completionFuture());
handlerPhases.add(nodeOperationTree.leaf());
}
try {
setupTasks(txnCtx, operationByServer, handlerPhases, handlerConsumers);
} catch (Throwable throwable) {
return Collections.singletonList(CompletableFuture.failedFuture(throwable));
}
return results;
}
use of io.crate.execution.dsl.phases.NodeOperationTree 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);
}
}
}
use of io.crate.execution.dsl.phases.NodeOperationTree in project crate by crate.
the class LogicalPlanner method doExecute.
private static void doExecute(LogicalPlan logicalPlan, DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults, boolean enableProfiling) {
NodeOperationTree nodeOpTree;
try {
nodeOpTree = getNodeOperationTree(logicalPlan, dependencies, plannerContext, params, subQueryResults);
} catch (Throwable t) {
consumer.accept(null, t);
return;
}
executeNodeOpTree(dependencies, plannerContext.transactionContext(), plannerContext.jobId(), consumer, enableProfiling, nodeOpTree);
}
Aggregations