Search in sources :

Example 1 with NodeOperationTree

use of io.crate.operation.NodeOperationTree in project crate by crate.

the class ExecutionPhasesTask method execute.

@Override
public void execute(BatchConsumer consumer, Row parameters) {
    assert nodeOperationTrees.size() == 1 : "must only have 1 NodeOperationTree for non-bulk operations";
    NodeOperationTree nodeOperationTree = nodeOperationTrees.get(0);
    Map<String, Collection<NodeOperation>> operationByServer = NodeOperationGrouper.groupByServer(nodeOperationTree.nodeOperations());
    List<ExecutionPhase> handlerPhases = Collections.singletonList(nodeOperationTree.leaf());
    List<BatchConsumer> handlerConsumers = Collections.singletonList(consumer);
    try {
        setupContext(operationByServer, handlerPhases, handlerConsumers);
    } catch (Throwable throwable) {
        consumer.accept(null, throwable);
    }
}
Also used : NodeOperationTree(io.crate.operation.NodeOperationTree) ExecutionPhase(io.crate.planner.node.ExecutionPhase) BatchConsumer(io.crate.data.BatchConsumer) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer)

Example 2 with NodeOperationTree

use of io.crate.operation.NodeOperationTree in project crate by crate.

the class ExecutionPhasesTask method executeBulk.

@Override
public List<CompletableFuture<Long>> executeBulk() {
    FluentIterable<NodeOperation> nodeOperations = FluentIterable.from(nodeOperationTrees).transformAndConcat(new Function<NodeOperationTree, Iterable<? extends NodeOperation>>() {

        @Nullable
        @Override
        public Iterable<? extends NodeOperation> apply(NodeOperationTree input) {
            return input.nodeOperations();
        }
    });
    Map<String, Collection<NodeOperation>> operationByServer = NodeOperationGrouper.groupByServer(nodeOperations);
    List<ExecutionPhase> handlerPhases = new ArrayList<>(nodeOperationTrees.size());
    List<BatchConsumer> handlerConsumers = new ArrayList<>(nodeOperationTrees.size());
    List<CompletableFuture<Long>> results = new ArrayList<>(nodeOperationTrees.size());
    for (NodeOperationTree nodeOperationTree : nodeOperationTrees) {
        CollectingBatchConsumer<?, Long> consumer = new CollectingBatchConsumer<>(Collectors.collectingAndThen(Collectors.summingLong(r -> ((long) r.get(0))), sum -> sum));
        handlerConsumers.add(consumer);
        results.add(consumer.resultFuture());
        handlerPhases.add(nodeOperationTree.leaf());
    }
    try {
        setupContext(operationByServer, handlerPhases, handlerConsumers);
    } catch (Throwable throwable) {
        return Collections.singletonList(CompletableFutures.failedFuture(throwable));
    }
    return results;
}
Also used : java.util(java.util) SharedShardContexts(io.crate.action.job.SharedShardContexts) ExecutionPhase(io.crate.planner.node.ExecutionPhase) CompletableFuture(java.util.concurrent.CompletableFuture) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) ContextPreparer(io.crate.action.job.ContextPreparer) FluentIterable(com.google.common.collect.FluentIterable) BatchConsumer(io.crate.data.BatchConsumer) ClusterService(org.elasticsearch.cluster.ClusterService) IndicesService(org.elasticsearch.indices.IndicesService) io.crate.jobs(io.crate.jobs) ESLogger(org.elasticsearch.common.logging.ESLogger) Nullable(javax.annotation.Nullable) NodeOperation(io.crate.operation.NodeOperation) Loggers(org.elasticsearch.common.logging.Loggers) TransportJobAction(io.crate.action.job.TransportJobAction) Bucket(io.crate.data.Bucket) Function(com.google.common.base.Function) CompletableFutures(io.crate.concurrent.CompletableFutures) Collectors(java.util.stream.Collectors) JobRequest(io.crate.action.job.JobRequest) NodeOperationGrouper(io.crate.planner.node.NodeOperationGrouper) Row(io.crate.data.Row) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer) ExecutionPhases(io.crate.planner.node.ExecutionPhases) NodeOperationTree(io.crate.operation.NodeOperationTree) Tuple(org.elasticsearch.common.collect.Tuple) JobTask(io.crate.executor.JobTask) FluentIterable(com.google.common.collect.FluentIterable) NodeOperation(io.crate.operation.NodeOperation) ExecutionPhase(io.crate.planner.node.ExecutionPhase) NodeOperationTree(io.crate.operation.NodeOperationTree) CompletableFuture(java.util.concurrent.CompletableFuture) Nullable(javax.annotation.Nullable) BatchConsumer(io.crate.data.BatchConsumer) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer)

Aggregations

BatchConsumer (io.crate.data.BatchConsumer)2 CollectingBatchConsumer (io.crate.data.CollectingBatchConsumer)2 NodeOperationTree (io.crate.operation.NodeOperationTree)2 ExecutionPhase (io.crate.planner.node.ExecutionPhase)2 Function (com.google.common.base.Function)1 FluentIterable (com.google.common.collect.FluentIterable)1 ContextPreparer (io.crate.action.job.ContextPreparer)1 JobRequest (io.crate.action.job.JobRequest)1 SharedShardContexts (io.crate.action.job.SharedShardContexts)1 TransportJobAction (io.crate.action.job.TransportJobAction)1 CompletableFutures (io.crate.concurrent.CompletableFutures)1 Bucket (io.crate.data.Bucket)1 Row (io.crate.data.Row)1 JobTask (io.crate.executor.JobTask)1 TransportKillJobsNodeAction (io.crate.executor.transport.kill.TransportKillJobsNodeAction)1 io.crate.jobs (io.crate.jobs)1 NodeOperation (io.crate.operation.NodeOperation)1 ExecutionPhases (io.crate.planner.node.ExecutionPhases)1 NodeOperationGrouper (io.crate.planner.node.NodeOperationGrouper)1 java.util (java.util)1