Search in sources :

Example 1 with NodeOperationTree

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

Example 2 with NodeOperationTree

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

Example 3 with NodeOperationTree

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;
}
Also used : TransactionContext(io.crate.metadata.TransactionContext) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) InstrumentedIndexSearcher(io.crate.execution.jobs.InstrumentedIndexSearcher) Tuple(io.crate.common.collections.Tuple) ListIterator(java.util.ListIterator) Task(io.crate.execution.jobs.Task) ClusterService(org.elasticsearch.cluster.service.ClusterService) ProfilingContext(io.crate.profile.ProfilingContext) CompletableFuture(java.util.concurrent.CompletableFuture) UnaryOperator(java.util.function.UnaryOperator) RootTask(io.crate.execution.jobs.RootTask) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) ArrayList(java.util.ArrayList) JobRequest(io.crate.execution.jobs.transport.JobRequest) JobSetup(io.crate.execution.jobs.JobSetup) Map(java.util.Map) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) IndicesService(org.elasticsearch.indices.IndicesService) TransportJobAction(io.crate.execution.jobs.transport.TransportJobAction) NodeOperationGrouper(io.crate.execution.dsl.phases.NodeOperationGrouper) DownstreamRXTask(io.crate.execution.jobs.DownstreamRXTask) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) CompletableFutures(io.crate.concurrent.CompletableFutures) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) QueryProfiler(org.elasticsearch.search.profile.query.QueryProfiler) TasksService(io.crate.execution.jobs.TasksService) RowConsumer(io.crate.data.RowConsumer) List(java.util.List) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) PageBucketReceiver(io.crate.execution.jobs.PageBucketReceiver) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhases(io.crate.execution.dsl.phases.ExecutionPhases) Collections(java.util.Collections) ArrayList(java.util.ArrayList) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) CompletableFuture(java.util.concurrent.CompletableFuture) NodeOperationTree(io.crate.execution.dsl.phases.NodeOperationTree) Collection(java.util.Collection) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) RowConsumer(io.crate.data.RowConsumer) CollectingRowConsumer(io.crate.data.CollectingRowConsumer)

Example 4 with NodeOperationTree

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);
        }
    }
}
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)

Example 5 with NodeOperationTree

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

Aggregations

NodeOperationTree (io.crate.execution.dsl.phases.NodeOperationTree)6 RowConsumer (io.crate.data.RowConsumer)3 ExecutionPlan (io.crate.planner.ExecutionPlan)3 CollectingRowConsumer (io.crate.data.CollectingRowConsumer)2 ExecutionPhase (io.crate.execution.dsl.phases.ExecutionPhase)2 Collection (java.util.Collection)2 UUID (java.util.UUID)2 BaseResultReceiver (io.crate.action.sql.BaseResultReceiver)1 RowConsumerToResultReceiver (io.crate.action.sql.RowConsumerToResultReceiver)1 Tuple (io.crate.common.collections.Tuple)1 CompletableFutures (io.crate.concurrent.CompletableFutures)1 Row1 (io.crate.data.Row1)1 ExecutionPhases (io.crate.execution.dsl.phases.ExecutionPhases)1 NodeOperation (io.crate.execution.dsl.phases.NodeOperation)1 NodeOperationGrouper (io.crate.execution.dsl.phases.NodeOperationGrouper)1 StreamBucket (io.crate.execution.engine.distribution.StreamBucket)1 DownstreamRXTask (io.crate.execution.jobs.DownstreamRXTask)1 InstrumentedIndexSearcher (io.crate.execution.jobs.InstrumentedIndexSearcher)1 JobSetup (io.crate.execution.jobs.JobSetup)1 PageBucketReceiver (io.crate.execution.jobs.PageBucketReceiver)1