Search in sources :

Example 6 with Streamer

use of io.crate.Streamer in project crate by crate.

the class JobSetup method registerContextPhases.

private void registerContextPhases(Iterable<? extends NodeOperation> nodeOperations, Context context) {
    for (NodeOperation nodeOperation : nodeOperations) {
        // context for nodeOperations without dependencies can be built immediately (e.g. FetchPhase)
        if (nodeOperation.downstreamExecutionPhaseId() == NodeOperation.NO_DOWNSTREAM) {
            LOGGER.trace("Building context for nodeOp without downstream: {}", nodeOperation);
            createContexts(nodeOperation.executionPhase(), context);
            context.opCtx.builtNodeOperations.set(nodeOperation.executionPhase().phaseId());
        }
        if (ExecutionPhases.hasDirectResponseDownstream(nodeOperation.downstreamNodes())) {
            var executionPhase = nodeOperation.executionPhase();
            CircuitBreaker breaker = breaker();
            int ramAccountingBlockSizeInBytes = BlockBasedRamAccounting.blockSizeInBytes(breaker.getLimit());
            var ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, executionPhase.label()), ramAccountingBlockSizeInBytes);
            Streamer<?>[] streamers = StreamerVisitor.streamersFromOutputs(executionPhase);
            SingleBucketBuilder bucketBuilder = new SingleBucketBuilder(streamers, ramAccounting);
            context.directResponseFutures.add(bucketBuilder.completionFuture().whenComplete((res, err) -> ramAccounting.close()));
            context.registerBatchConsumer(nodeOperation.downstreamExecutionPhaseId(), bucketBuilder);
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) DistributionType(io.crate.planner.distribution.DistributionType) SessionSettings(io.crate.metadata.settings.SessionSettings) FetchPhase(io.crate.execution.dsl.phases.FetchPhase) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Projections.nodeProjections(io.crate.execution.dsl.projection.Projections.nodeProjections) MapSideDataCollectOperation(io.crate.execution.engine.collect.MapSideDataCollectOperation) ProjectorFactory(io.crate.execution.engine.pipeline.ProjectorFactory) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) Projections.shardProjections(io.crate.execution.dsl.projection.Projections.shardProjections) IntArrayList(com.carrotsearch.hppc.IntArrayList) Map(java.util.Map) Collector(java.util.stream.Collector) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) ProjectingRowConsumer(io.crate.execution.engine.pipeline.ProjectingRowConsumer) PKLookupOperation(io.crate.execution.engine.collect.PKLookupOperation) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) Logger(org.apache.logging.log4j.Logger) Row(io.crate.data.Row) ExecutionPhase(io.crate.execution.dsl.phases.ExecutionPhase) IntObjectCursor(com.carrotsearch.hppc.cursors.IntObjectCursor) Tuple(io.crate.common.collections.Tuple) NestedLoopOperation(io.crate.execution.engine.join.NestedLoopOperation) ClusterService(org.elasticsearch.cluster.service.ClusterService) Operation(io.crate.metadata.table.Operation) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) ArrayList(java.util.ArrayList) Routing(io.crate.metadata.Routing) RowCellsAccountingWithEstimators(io.crate.breaker.RowCellsAccountingWithEstimators) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) IndicesService(org.elasticsearch.indices.IndicesService) LongObjectHashMap(com.carrotsearch.hppc.LongObjectHashMap) Nullable(javax.annotation.Nullable) Executor(java.util.concurrent.Executor) SystemCollectSource(io.crate.execution.engine.collect.sources.SystemCollectSource) RamAccounting(io.crate.breaker.RamAccounting) IncrementalPageBucketReceiver(io.crate.execution.IncrementalPageBucketReceiver) ConcurrentRamAccounting(io.crate.breaker.ConcurrentRamAccounting) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) IntObjectHashMap(com.carrotsearch.hppc.IntObjectHashMap) Schemas(io.crate.metadata.Schemas) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) AggregationPipe(io.crate.execution.engine.aggregation.AggregationPipe) InputFactory(io.crate.expression.InputFactory) MemoryManagerFactory(io.crate.memory.MemoryManagerFactory) TransactionContext(io.crate.metadata.TransactionContext) PKAndVersion(io.crate.planner.operators.PKAndVersion) HashJoinPhase(io.crate.execution.dsl.phases.HashJoinPhase) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) MergePhase(io.crate.execution.dsl.phases.MergePhase) Settings(org.elasticsearch.common.settings.Settings) DistributingConsumerFactory(io.crate.execution.engine.distribution.DistributingConsumerFactory) Locale(java.util.Locale) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LongObjectMap(com.carrotsearch.hppc.LongObjectMap) NodeContext(io.crate.metadata.NodeContext) HashJoinOperation(io.crate.execution.engine.join.HashJoinOperation) Streamer(io.crate.Streamer) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IntContainer(com.carrotsearch.hppc.IntContainer) NestedLoopPhase(io.crate.execution.dsl.phases.NestedLoopPhase) UUID(java.util.UUID) CollectTask(io.crate.execution.engine.collect.CollectTask) Objects(java.util.Objects) List(java.util.List) ExecutionPhaseVisitor(io.crate.execution.dsl.phases.ExecutionPhaseVisitor) Projection(io.crate.execution.dsl.projection.Projection) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Paging(io.crate.data.Paging) FetchTask(io.crate.execution.engine.fetch.FetchTask) StreamBucket(io.crate.execution.engine.distribution.StreamBucket) SingleBucketBuilder(io.crate.execution.engine.distribution.SingleBucketBuilder) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) CompletableFuture(java.util.concurrent.CompletableFuture) CountPhase(io.crate.execution.dsl.phases.CountPhase) Inject(org.elasticsearch.common.inject.Inject) ObjectProcedure(com.carrotsearch.hppc.procedures.ObjectProcedure) Node(org.elasticsearch.node.Node) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) PKLookupPhase(io.crate.execution.dsl.phases.PKLookupPhase) UpstreamPhase(io.crate.execution.dsl.phases.UpstreamPhase) CountOperation(io.crate.execution.engine.collect.count.CountOperation) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) StreamerVisitor(io.crate.planner.node.StreamerVisitor) IntHashSet(com.carrotsearch.hppc.IntHashSet) ShardCollectSource(io.crate.execution.engine.collect.sources.ShardCollectSource) IntCollection(com.carrotsearch.hppc.IntCollection) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) ProjectionToProjectorVisitor(io.crate.execution.engine.pipeline.ProjectionToProjectorVisitor) MemoryManager(io.crate.memory.MemoryManager) TransportActionProvider(io.crate.execution.TransportActionProvider) PagingIterator(io.crate.execution.engine.distribution.merge.PagingIterator) IntObjectMap(com.carrotsearch.hppc.IntObjectMap) RowConsumer(io.crate.data.RowConsumer) RowFilter(io.crate.expression.RowFilter) BitSet(java.util.BitSet) ExecutionPhases(io.crate.execution.dsl.phases.ExecutionPhases) LogManager(org.apache.logging.log4j.LogManager) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) Streamer(io.crate.Streamer) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) SingleBucketBuilder(io.crate.execution.engine.distribution.SingleBucketBuilder)

Example 7 with Streamer

use of io.crate.Streamer in project crate by crate.

the class HyperLogLogDistinctAggregationTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    HyperLogLogDistinctAggregation.HllState hllState1 = new HyperLogLogDistinctAggregation.HllState(DataTypes.IP, true);
    hllState1.init(memoryManager, HyperLogLogPlusPlus.DEFAULT_PRECISION);
    BytesStreamOutput out = new BytesStreamOutput();
    Streamer streamer = HyperLogLogDistinctAggregation.HllStateType.INSTANCE.streamer();
    streamer.writeValueTo(out, hllState1);
    StreamInput in = out.bytes().streamInput();
    HyperLogLogDistinctAggregation.HllState hllState2 = (HyperLogLogDistinctAggregation.HllState) streamer.readValueFrom(in);
    // test that murmur3hash and HLL++ is correctly initialized with streamed dataType and version
    hllState1.add("127.0.0.1");
    hllState2.add("127.0.0.1");
    assertThat(hllState2.value(), is(hllState1.value()));
}
Also used : Streamer(io.crate.Streamer) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 8 with Streamer

use of io.crate.Streamer in project crate by crate.

the class TransportAnalyzeAction method fetchSamples.

private CompletableFuture<Samples> fetchSamples(RelationName relationName, List<Reference> columns) {
    FutureActionListener<FetchSampleResponse, Samples> listener = new FutureActionListener<>(FetchSampleResponse::samples);
    List<DiscoveryNode> nodesOn41OrAfter = StreamSupport.stream(clusterService.state().nodes().spliterator(), false).filter(x -> x.getVersion().onOrAfter(Version.V_4_1_0)).collect(Collectors.toList());
    MultiActionListener<FetchSampleResponse, ?, FetchSampleResponse> multiListener = new MultiActionListener<>(nodesOn41OrAfter.size(), Collectors.reducing(new FetchSampleResponse(Samples.EMPTY), (FetchSampleResponse s1, FetchSampleResponse s2) -> FetchSampleResponse.merge(TransportAnalyzeAction.NUM_SAMPLES, s1, s2)), listener);
    List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
    ActionListenerResponseHandler<FetchSampleResponse> responseHandler = new ActionListenerResponseHandler<>(multiListener, in -> new FetchSampleResponse(streamers, in), ThreadPool.Names.SAME);
    for (DiscoveryNode node : nodesOn41OrAfter) {
        transportService.sendRequest(node, FETCH_SAMPLES, new FetchSampleRequest(relationName, columns, TransportAnalyzeAction.NUM_SAMPLES), responseHandler);
    }
    return listener;
}
Also used : Arrays(java.util.Arrays) RelationName(io.crate.metadata.RelationName) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) Symbols(io.crate.expression.symbol.Symbols) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) FutureActionListener(io.crate.action.FutureActionListener) SchemaInfo(io.crate.metadata.table.SchemaInfo) TableInfo(io.crate.metadata.table.TableInfo) Streamer(io.crate.Streamer) NodeActionRequestHandler(io.crate.execution.support.NodeActionRequestHandler) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) CompletableFutures(io.crate.concurrent.CompletableFutures) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Collectors(java.util.stream.Collectors) MultiActionListener(io.crate.execution.support.MultiActionListener) List(java.util.List) Version(org.elasticsearch.Version) Row(io.crate.data.Row) AnalyzeRequest(io.crate.execution.ddl.AnalyzeRequest) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MultiActionListener(io.crate.execution.support.MultiActionListener) FutureActionListener(io.crate.action.FutureActionListener) Streamer(io.crate.Streamer) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler)

Example 9 with Streamer

use of io.crate.Streamer in project crate by crate.

the class RowType method writeValueTo.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void writeValueTo(StreamOutput out, Row row) throws IOException {
    assert row.numColumns() == fieldTypes.size() : "Row that should be streamed must have the same number of columns as the rowType contains fieldTypes";
    for (int i = 0; i < fieldTypes.size(); i++) {
        Streamer streamer = fieldTypes.get(i).streamer();
        streamer.writeValueTo(out, row.get(i));
    }
}
Also used : Streamer(io.crate.Streamer)

Example 10 with Streamer

use of io.crate.Streamer in project crate by crate.

the class DistributedResultRequestTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    Streamer<?>[] streamers = new Streamer[] { DataTypes.STRING.streamer() };
    UUID uuid = UUID.randomUUID();
    StreamBucket.Builder builder = new StreamBucket.Builder(streamers, RamAccounting.NO_ACCOUNTING);
    builder.add(new RowN(new Object[] { "ab" }));
    builder.add(new RowN(new Object[] { null }));
    builder.add(new RowN(new Object[] { "cd" }));
    DistributedResultRequest r1 = new DistributedResultRequest(uuid, 1, (byte) 3, 1, builder.build(), false);
    BytesStreamOutput out = new BytesStreamOutput();
    r1.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    DistributedResultRequest r2 = new DistributedResultRequest(in);
    assertEquals(r1.readRows(streamers).size(), r2.readRows(streamers).size());
    assertThat(r1.isLast(), is(r2.isLast()));
    assertThat(r1.executionPhaseInputId(), is(r2.executionPhaseInputId()));
    assertThat(r2.readRows(streamers), contains(isRow("ab"), isNullRow(), isRow("cd")));
}
Also used : RowN(io.crate.data.RowN) Streamer(io.crate.Streamer) StreamInput(org.elasticsearch.common.io.stream.StreamInput) UUID(java.util.UUID) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Aggregations

Streamer (io.crate.Streamer)20 Test (org.junit.Test)13 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)6 StreamInput (org.elasticsearch.common.io.stream.StreamInput)6 Row (io.crate.data.Row)4 DistResultRXTask (io.crate.execution.jobs.DistResultRXTask)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 TestingRowConsumer (io.crate.testing.TestingRowConsumer)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 UUID (java.util.UUID)3 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)2 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)2 BlockBasedRamAccounting (io.crate.breaker.BlockBasedRamAccounting)2 PageDownstreamContext (io.crate.jobs.PageDownstreamContext)2 Reference (io.crate.metadata.Reference)2 RelationName (io.crate.metadata.RelationName)2 Routing (io.crate.metadata.Routing)2 Schemas (io.crate.metadata.Schemas)2