Search in sources :

Example 1 with CollectingRowConsumer

use of io.crate.data.CollectingRowConsumer in project crate by crate.

the class RemoteCollectorFactory method retrieveRows.

private CompletableFuture<List<Row>> retrieveRows(ShardRouting activePrimaryRouting, RoutedCollectPhase collectPhase, CollectTask collectTask, ShardCollectorProviderFactory shardCollectorProviderFactory) {
    Collector<Row, ?, List<Object[]>> listCollector = Collectors.mapping(Row::materialize, Collectors.toList());
    CollectingRowConsumer<?, List<Object[]>> consumer = new CollectingRowConsumer<>(listCollector);
    String nodeId = activePrimaryRouting.currentNodeId();
    String localNodeId = clusterService.localNode().getId();
    if (localNodeId.equalsIgnoreCase(nodeId)) {
        var indexShard = indicesService.indexServiceSafe(activePrimaryRouting.index()).getShard(activePrimaryRouting.shardId().id());
        var collectorProvider = shardCollectorProviderFactory.create(indexShard);
        CompletableFuture<BatchIterator<Row>> it;
        try {
            it = collectorProvider.getFutureIterator(collectPhase, consumer.requiresScroll(), collectTask);
        } catch (Exception e) {
            return Exceptions.rethrowRuntimeException(e);
        }
        it.whenComplete(consumer);
    } else {
        UUID childJobId = UUIDs.dirtyUUID();
        RemoteCollector remoteCollector = new RemoteCollector(childJobId, collectTask.txnCtx().sessionSettings(), localNodeId, nodeId, transportActionProvider.transportJobInitAction(), transportActionProvider.transportKillJobsNodeAction(), searchTp, tasksService, collectTask.getRamAccounting(), consumer, createRemoteCollectPhase(childJobId, collectPhase, activePrimaryRouting.shardId(), nodeId));
        remoteCollector.doCollect();
    }
    return consumer.completionFuture().thenApply(rows -> Lists2.mapLazy(rows, Buckets.arrayToSharedRow()));
}
Also used : BatchIterator(io.crate.data.BatchIterator) CollectingBatchIterator(io.crate.data.CollectingBatchIterator) RemoteCollector(io.crate.execution.engine.collect.collectors.RemoteCollector) ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) List(java.util.List) Row(io.crate.data.Row) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) UUID(java.util.UUID)

Example 2 with CollectingRowConsumer

use of io.crate.data.CollectingRowConsumer 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 3 with CollectingRowConsumer

use of io.crate.data.CollectingRowConsumer in project crate by crate.

the class MultiPhaseExecutor method execute.

public static CompletableFuture<SubQueryResults> execute(Map<LogicalPlan, SelectSymbol> dependencies, DependencyCarrier executor, PlannerContext plannerContext, Row params) {
    List<CompletableFuture<?>> dependencyFutures = new ArrayList<>(dependencies.size());
    IdentityHashMap<SelectSymbol, Object> valueBySubQuery = new IdentityHashMap<>();
    for (Map.Entry<LogicalPlan, SelectSymbol> entry : dependencies.entrySet()) {
        LogicalPlan depPlan = entry.getKey();
        SelectSymbol selectSymbol = entry.getValue();
        CollectingRowConsumer<?, ?> rowConsumer = getConsumer(selectSymbol.getResultType());
        depPlan.execute(executor, PlannerContext.forSubPlan(plannerContext), rowConsumer, params, SubQueryResults.EMPTY);
        dependencyFutures.add(rowConsumer.completionFuture().thenAccept(val -> {
            synchronized (valueBySubQuery) {
                valueBySubQuery.put(selectSymbol, val);
            }
        }));
    }
    return CompletableFuture.allOf(dependencyFutures.toArray(new CompletableFuture[0])).thenApply(ignored -> new SubQueryResults(valueBySubQuery));
}
Also used : SelectSymbol(io.crate.expression.symbol.SelectSymbol) LogicalPlan(io.crate.planner.operators.LogicalPlan) IdentityHashMap(java.util.IdentityHashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CollectingRowConsumer(io.crate.data.CollectingRowConsumer) ArrayList(java.util.ArrayList) DependencyCarrier(io.crate.planner.DependencyCarrier) List(java.util.List) Row(io.crate.data.Row) PlannerContext(io.crate.planner.PlannerContext) Map(java.util.Map) SelectSymbol(io.crate.expression.symbol.SelectSymbol) SubQueryResults(io.crate.planner.operators.SubQueryResults) FirstColumnConsumers(io.crate.execution.engine.FirstColumnConsumers) IdentityHashMap(java.util.IdentityHashMap) SubQueryResults(io.crate.planner.operators.SubQueryResults) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) LogicalPlan(io.crate.planner.operators.LogicalPlan) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Aggregations

CollectingRowConsumer (io.crate.data.CollectingRowConsumer)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Row (io.crate.data.Row)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 Tuple (io.crate.common.collections.Tuple)1 CompletableFutures (io.crate.concurrent.CompletableFutures)1 BatchIterator (io.crate.data.BatchIterator)1 CollectingBatchIterator (io.crate.data.CollectingBatchIterator)1 RowConsumer (io.crate.data.RowConsumer)1 ExecutionPhase (io.crate.execution.dsl.phases.ExecutionPhase)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 NodeOperationTree (io.crate.execution.dsl.phases.NodeOperationTree)1 FirstColumnConsumers (io.crate.execution.engine.FirstColumnConsumers)1 RemoteCollector (io.crate.execution.engine.collect.collectors.RemoteCollector)1