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