Search in sources :

Example 16 with Streamer

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

the class CountAggregationTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    CountAggregation.LongState l1 = new CountAggregation.LongState(12345L);
    BytesStreamOutput out = new BytesStreamOutput();
    Streamer streamer = CountAggregation.LongStateType.INSTANCE.streamer();
    streamer.writeValueTo(out, l1);
    StreamInput in = StreamInput.wrap(out.bytes());
    CountAggregation.LongState l2 = (CountAggregation.LongState) streamer.readValueFrom(in);
    assertEquals(l1.value, l2.value);
}
Also used : Streamer(io.crate.Streamer) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) AggregationTest(io.crate.operation.aggregation.AggregationTest) Test(org.junit.Test)

Example 17 with Streamer

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

the class DistributingConsumerTest method testDistributingConsumerForwardsFailure.

@Test
public void testDistributingConsumerForwardsFailure() throws Exception {
    Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
    TestingRowConsumer collectingConsumer = new TestingRowConsumer();
    DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
    TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
    DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
    distributingConsumer.accept(null, new CompletionException(new IllegalArgumentException("foobar")));
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("foobar");
    collectingConsumer.getResult();
}
Also used : Streamer(io.crate.Streamer) CompletionException(java.util.concurrent.CompletionException) DistResultRXTask(io.crate.execution.jobs.DistResultRXTask) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 18 with Streamer

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

the class DistributingConsumerTest method test_exception_on_loadNextBatch_is_forwarded.

@Test
public void test_exception_on_loadNextBatch_is_forwarded() throws Exception {
    Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
    TestingRowConsumer collectingConsumer = new TestingRowConsumer();
    DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
    TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
    DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
    BatchSimulatingIterator<Row> batchSimulatingIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 5), 2, 3, executorService) {

        @Override
        public CompletionStage<?> loadNextBatch() {
            throw new CircuitBreakingException("data too large");
        }
    };
    distributingConsumer.accept(batchSimulatingIterator, null);
    expectedException.expect(CircuitBreakingException.class);
    collectingConsumer.getResult();
}
Also used : Streamer(io.crate.Streamer) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) Row(io.crate.data.Row) DistResultRXTask(io.crate.execution.jobs.DistResultRXTask) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 19 with Streamer

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

the class TDigestStateTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    TDigestState digestState1 = new TDigestState(250, new double[] { 0.5, 0.8 });
    BytesStreamOutput out = new BytesStreamOutput();
    TDigestStateType digestStateType = TDigestStateType.INSTANCE;
    Streamer streamer = digestStateType.streamer();
    streamer.writeValueTo(out, digestState1);
    StreamInput in = out.bytes().streamInput();
    TDigestState digestState2 = (TDigestState) streamer.readValueFrom(in);
    assertEquals(digestState1.compression(), digestState2.compression(), 0.001d);
    assertEquals(digestState1.fractions()[0], digestState2.fractions()[0], 0.001d);
    assertEquals(digestState1.fractions()[1], digestState2.fractions()[1], 0.001d);
}
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 20 with Streamer

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

the class ReservoirSampler method getSamples.

public Samples getSamples(RelationName relationName, List<Reference> columns, int maxSamples) {
    TableInfo table;
    try {
        table = schemas.getTableInfo(relationName);
    } catch (RelationUnknown e) {
        return Samples.EMPTY;
    }
    if (!(table instanceof DocTableInfo)) {
        return Samples.EMPTY;
    }
    DocTableInfo docTable = (DocTableInfo) table;
    Random random = Randomness.get();
    Metadata metadata = clusterService.state().metadata();
    CoordinatorTxnCtx coordinatorTxnCtx = CoordinatorTxnCtx.systemTransactionContext();
    List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
    List<Engine.Searcher> searchersToRelease = new ArrayList<>();
    CircuitBreaker breaker = circuitBreakerService.getBreaker(HierarchyCircuitBreakerService.QUERY);
    RamAccounting ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, "Reservoir-sampling"), MAX_BLOCK_SIZE_IN_BYTES);
    try {
        return getSamples(columns, maxSamples, docTable, random, metadata, coordinatorTxnCtx, streamers, searchersToRelease, ramAccounting);
    } finally {
        ramAccounting.close();
        for (Engine.Searcher searcher : searchersToRelease) {
            searcher.close();
        }
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) RamAccounting(io.crate.breaker.RamAccounting) RelationUnknown(io.crate.exceptions.RelationUnknown) Metadata(org.elasticsearch.cluster.metadata.Metadata) ArrayList(java.util.ArrayList) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) Random(java.util.Random) Streamer(io.crate.Streamer) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) Engine(org.elasticsearch.index.engine.Engine)

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