Search in sources :

Example 1 with BatchConsumer

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

the class ContextPreparer method prepareOnHandler.

public List<CompletableFuture<Bucket>> prepareOnHandler(Iterable<? extends NodeOperation> nodeOperations, JobExecutionContext.Builder contextBuilder, List<Tuple<ExecutionPhase, BatchConsumer>> handlerPhases, SharedShardContexts sharedShardContexts) {
    ContextPreparer.PreparerContext preparerContext = new PreparerContext(clusterService.localNode().getId(), contextBuilder, logger, distributingDownstreamFactory, nodeOperations, sharedShardContexts);
    for (Tuple<ExecutionPhase, BatchConsumer> handlerPhase : handlerPhases) {
        preparerContext.registerLeaf(handlerPhase.v1(), handlerPhase.v2());
    }
    registerContextPhases(nodeOperations, preparerContext);
    logger.trace("prepareOnHandler: nodeOperations={}, handlerPhases={}, targetSourceMap={}", nodeOperations, handlerPhases, preparerContext.opCtx.targetToSourceMap);
    IntHashSet leafs = new IntHashSet();
    for (Tuple<ExecutionPhase, BatchConsumer> handlerPhase : handlerPhases) {
        ExecutionPhase phase = handlerPhase.v1();
        createContexts(phase, preparerContext);
        leafs.add(phase.phaseId());
    }
    leafs.addAll(preparerContext.opCtx.findLeafs());
    for (IntCursor cursor : leafs) {
        prepareSourceOperations(cursor.value, preparerContext);
    }
    assert preparerContext.opCtx.allNodeOperationContextsBuilt() : "some nodeOperations haven't been processed";
    return preparerContext.directResponseFutures;
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) ExecutionPhase(io.crate.planner.node.ExecutionPhase) BatchConsumer(io.crate.data.BatchConsumer) ProjectingBatchConsumer(io.crate.operation.projectors.ProjectingBatchConsumer)

Example 2 with BatchConsumer

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

the class DistributingDownstreamFactoryTest method testCreateDownstreamMultipleNode.

@Test
public void testCreateDownstreamMultipleNode() throws Exception {
    BatchConsumer downstream = createDownstream(ImmutableSet.of("downstream_node1", "downstream_node2"));
    assertThat(((DistributingConsumer) downstream).multiBucketBuilder, instanceOf(ModuloBucketBuilder.class));
}
Also used : BatchConsumer(io.crate.data.BatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with BatchConsumer

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

the class ExecutionPhasesTask method createHandlerPhaseAndReceivers.

private List<Tuple<ExecutionPhase, BatchConsumer>> createHandlerPhaseAndReceivers(List<ExecutionPhase> handlerPhases, List<BatchConsumer> handlerReceivers, InitializationTracker initializationTracker) {
    List<Tuple<ExecutionPhase, BatchConsumer>> handlerPhaseAndReceiver = new ArrayList<>();
    ListIterator<BatchConsumer> consumerIt = handlerReceivers.listIterator();
    for (ExecutionPhase handlerPhase : handlerPhases) {
        InterceptingBatchConsumer interceptingBatchConsumer = new InterceptingBatchConsumer(jobId(), consumerIt.next(), initializationTracker, transportKillJobsNodeAction);
        handlerPhaseAndReceiver.add(new Tuple<>(handlerPhase, interceptingBatchConsumer));
    }
    return handlerPhaseAndReceiver;
}
Also used : ExecutionPhase(io.crate.planner.node.ExecutionPhase) Tuple(org.elasticsearch.common.collect.Tuple) BatchConsumer(io.crate.data.BatchConsumer) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer)

Example 4 with BatchConsumer

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

the class SystemCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase phase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    // sys.operations can contain a _node column - these refs need to be normalized into literals
    EvaluatingNormalizer normalizer = new EvaluatingNormalizer(functions, RowGranularity.DOC, ReplaceMode.COPY, new NodeSysReferenceResolver(nodeSysExpression), null);
    final RoutedCollectPhase routedCollectPhase = collectPhase.normalize(normalizer, null);
    Map<String, Map<String, List<Integer>>> locations = collectPhase.routing().locations();
    String table = Iterables.getOnlyElement(locations.get(clusterService.localNode().getId()).keySet());
    Supplier<CompletableFuture<? extends Iterable<?>>> iterableGetter = iterableGetters.get(table);
    assert iterableGetter != null : "iterableGetter for " + table + " must exist";
    boolean requiresScroll = consumer.requiresScroll();
    return BatchIteratorCollectorBridge.newInstance(() -> iterableGetter.get().thenApply(dataIterable -> RowsBatchIterator.newInstance(dataIterableToRowsIterable(routedCollectPhase, requiresScroll, dataIterable), collectPhase.toCollect().size())), consumer);
}
Also used : BatchIteratorCollectorBridge(io.crate.operation.collect.BatchIteratorCollectorBridge) Iterables(com.google.common.collect.Iterables) CompletableFuture(java.util.concurrent.CompletableFuture) ReplaceMode(io.crate.metadata.ReplaceMode) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Inject(org.elasticsearch.common.inject.Inject) JobCollectContext(io.crate.operation.collect.JobCollectContext) SysSnapshots(io.crate.operation.reference.sys.snapshot.SysSnapshots) ImmutableList(com.google.common.collect.ImmutableList) Functions(io.crate.metadata.Functions) BatchConsumer(io.crate.data.BatchConsumer) io.crate.metadata.sys(io.crate.metadata.sys) NodeSysReferenceResolver(io.crate.operation.reference.sys.node.local.NodeSysReferenceResolver) ClusterService(org.elasticsearch.cluster.ClusterService) Map(java.util.Map) SysRowUpdater(io.crate.operation.reference.sys.SysRowUpdater) SysRepositoriesService(io.crate.operation.reference.sys.repositories.SysRepositoriesService) RowsBatchIterator(io.crate.data.RowsBatchIterator) CrateCollector(io.crate.operation.collect.CrateCollector) SysCheck(io.crate.operation.reference.sys.check.SysCheck) ImmutableMap(com.google.common.collect.ImmutableMap) RowsTransformer(io.crate.operation.collect.RowsTransformer) Set(java.util.Set) SysChecker(io.crate.operation.reference.sys.check.SysChecker) TableIdent(io.crate.metadata.TableIdent) RowContextReferenceResolver(io.crate.operation.reference.sys.RowContextReferenceResolver) JobsLogs(io.crate.operation.collect.stats.JobsLogs) CollectPhase(io.crate.planner.node.dql.CollectPhase) PgCatalogTables(io.crate.metadata.pg_catalog.PgCatalogTables) InputFactory(io.crate.operation.InputFactory) SysNodeChecks(io.crate.operation.reference.sys.check.node.SysNodeChecks) io.crate.metadata.information(io.crate.metadata.information) SummitsIterable(io.crate.operation.collect.files.SummitsIterable) List(java.util.List) RowGranularity(io.crate.metadata.RowGranularity) Row(io.crate.data.Row) NodeSysExpression(io.crate.operation.reference.sys.node.local.NodeSysExpression) PgTypeTable(io.crate.metadata.pg_catalog.PgTypeTable) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) CompletableFuture(java.util.concurrent.CompletableFuture) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) SummitsIterable(io.crate.operation.collect.files.SummitsIterable) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) NodeSysReferenceResolver(io.crate.operation.reference.sys.node.local.NodeSysReferenceResolver)

Example 5 with BatchConsumer

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

the class BatchPortal method sync.

@Override
public CompletableFuture<Void> sync(Planner planner, JobsLogs jobsLogs) {
    CountdownFutureCallback completionCallback = new CountdownFutureCallback(analysis.size());
    for (int i = 0; i < analysis.size(); i++) {
        UUID jobId = UUID.randomUUID();
        Plan plan;
        String stmt = queries.get(i);
        try {
            plan = planner.plan(analysis.get(i), jobId, 0, 0);
        } catch (Throwable t) {
            jobsLogs.logPreExecutionFailure(jobId, stmt, SQLExceptions.messageOf(t));
            throw t;
        }
        ResultReceiver resultReceiver = resultReceivers.get(i);
        jobsLogs.logExecutionStart(jobId, stmt);
        JobsLogsUpdateListener jobsLogsUpdateListener = new JobsLogsUpdateListener(jobId, jobsLogs);
        resultReceiver.completionFuture().whenComplete(jobsLogsUpdateListener).whenComplete(completionCallback);
        BatchConsumer consumer = new BatchConsumerToResultReceiver(resultReceiver, 0);
        portalContext.getExecutor().execute(plan, consumer, new RowN(batchParams.toArray()));
    }
    synced = true;
    return completionCallback;
}
Also used : RowN(io.crate.data.RowN) CountdownFutureCallback(io.crate.concurrent.CountdownFutureCallback) BatchConsumerToResultReceiver(io.crate.action.sql.BatchConsumerToResultReceiver) UUID(java.util.UUID) Plan(io.crate.planner.Plan) BatchConsumerToResultReceiver(io.crate.action.sql.BatchConsumerToResultReceiver) ResultReceiver(io.crate.action.sql.ResultReceiver) BatchConsumer(io.crate.data.BatchConsumer)

Aggregations

BatchConsumer (io.crate.data.BatchConsumer)11 ExecutionPhase (io.crate.planner.node.ExecutionPhase)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 Test (org.junit.Test)4 CollectingBatchConsumer (io.crate.data.CollectingBatchConsumer)3 CompositeBatchIterator (io.crate.data.CompositeBatchIterator)2 Row (io.crate.data.Row)2 NodeOperationTree (io.crate.operation.NodeOperationTree)2 ProjectingBatchConsumer (io.crate.operation.projectors.ProjectingBatchConsumer)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 Function (com.google.common.base.Function)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)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 BatchConsumerToResultReceiver (io.crate.action.sql.BatchConsumerToResultReceiver)1