Search in sources :

Example 21 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class ProjectionToProjectorVisitorTest method testAggregationProjector.

@Test
public void testAggregationProjector() throws Exception {
    AggregationProjection projection = new AggregationProjection(Arrays.asList(new Aggregation(avgSignature, avgSignature.getReturnType().createType(), Collections.singletonList(new InputColumn(1))), new Aggregation(CountAggregation.SIGNATURE, CountAggregation.SIGNATURE.getReturnType().createType(), Collections.singletonList(new InputColumn(0)))), RowGranularity.SHARD, AggregateMode.ITER_FINAL);
    Projector projector = visitor.create(projection, txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, UUID.randomUUID());
    assertThat(projector, instanceOf(AggregationPipe.class));
    BatchIterator<Row> batchIterator = projector.apply(InMemoryBatchIterator.of(new CollectionBucket(Arrays.asList($("foo", 10), $("bar", 20))), SENTINEL, true));
    TestingRowConsumer consumer = new TestingRowConsumer();
    consumer.accept(batchIterator, null);
    Bucket rows = consumer.getBucket();
    assertThat(rows.size(), is(1));
    assertThat(rows, contains(isRow(15.0, 2L)));
}
Also used : Aggregation(io.crate.expression.symbol.Aggregation) CountAggregation(io.crate.execution.engine.aggregation.impl.CountAggregation) Projector(io.crate.data.Projector) SortingProjector(io.crate.execution.engine.sort.SortingProjector) SortingTopNProjector(io.crate.execution.engine.sort.SortingTopNProjector) GroupingProjector(io.crate.execution.engine.aggregation.GroupingProjector) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) InputColumn(io.crate.expression.symbol.InputColumn) Row(io.crate.data.Row) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) AggregationPipe(io.crate.execution.engine.aggregation.AggregationPipe) CollectionBucket(io.crate.data.CollectionBucket) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 22 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class DistResultRXTaskTest method testPagingWithSortedPagingIterator.

@Test
public void testPagingWithSortedPagingIterator() throws Throwable {
    TestingRowConsumer batchConsumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(batchConsumer, new SortedPagingIterator<>(Comparator.comparingInt(r -> (int) r.get(0)), false), 2);
    Bucket b1 = new ArrayBucket(new Object[][] { new Object[] { 1 }, new Object[] { 1 } });
    Bucket b11 = new ArrayBucket(new Object[][] { new Object[] { 2 }, new Object[] { 2 } });
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    bucketReceiver.setBucket(0, b1, false, needMore -> {
        if (needMore) {
            bucketReceiver.setBucket(0, b11, true, mock(PageResultListener.class));
        }
    });
    Bucket b2 = new ArrayBucket(new Object[][] { new Object[] { 4 } });
    bucketReceiver.setBucket(1, b2, true, mock(PageResultListener.class));
    List<Object[]> result = batchConsumer.getResult();
    assertThat(TestingHelpers.printedTable(new CollectionBucket(result)), is("1\n" + "1\n" + "2\n" + "2\n" + "4\n"));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) ArrayBucket(io.crate.data.ArrayBucket) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test)

Example 23 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class DistResultRXTaskTest method test_batch_iterator_is_completed_exceptionally_if_merge_buckets_on_next_page_fails.

@Test
public void test_batch_iterator_is_completed_exceptionally_if_merge_buckets_on_next_page_fails() throws Exception {
    TestingRowConsumer batchConsumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(batchConsumer, new FailOnMergePagingIterator<>(2), 2);
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    PageResultListener pageResultListener = mock(PageResultListener.class);
    Bucket bucket = new CollectionBucket(Collections.singletonList(new Object[] { "foo" }));
    bucketReceiver.setBucket(0, bucket, false, pageResultListener);
    bucketReceiver.setBucket(1, bucket, false, pageResultListener);
    bucketReceiver.setBucket(0, bucket, true, pageResultListener);
    bucketReceiver.setBucket(1, bucket, true, pageResultListener);
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("raised on merge");
    batchConsumer.getResult();
}
Also used : Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) ArrayBucket(io.crate.data.ArrayBucket) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test)

Example 24 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class DistResultRXTaskTest method test_batch_iterator_is_completed_exceptionally_if_first_merge_buckets_fails.

@Test
public void test_batch_iterator_is_completed_exceptionally_if_first_merge_buckets_fails() throws Exception {
    TestingRowConsumer batchConsumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(batchConsumer, new FailOnMergePagingIterator<>(1), 1);
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    PageResultListener pageResultListener = mock(PageResultListener.class);
    Bucket bucket = new CollectionBucket(Collections.singletonList(new Object[] { "foo" }));
    bucketReceiver.setBucket(0, bucket, true, pageResultListener);
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("raised on merge");
    batchConsumer.getResult();
}
Also used : Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) ArrayBucket(io.crate.data.ArrayBucket) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test)

Example 25 with TestingRowConsumer

use of io.crate.testing.TestingRowConsumer in project crate by crate.

the class DistResultRXTaskTest method testListenersCalledWhenOtherUpstreamIsFailing.

@Test
public void testListenersCalledWhenOtherUpstreamIsFailing() throws Exception {
    TestingRowConsumer consumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(consumer, PassThroughPagingIterator.oneShot(), 2);
    PageResultListener listener = mock(PageResultListener.class);
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    bucketReceiver.setBucket(0, Bucket.EMPTY, false, listener);
    bucketReceiver.kill(new Exception("dummy"));
    verify(listener, times(1)).needMore(false);
}
Also used : CompletionException(java.util.concurrent.CompletionException) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Aggregations

TestingRowConsumer (io.crate.testing.TestingRowConsumer)64 Test (org.junit.Test)55 Row (io.crate.data.Row)24 CollectionBucket (io.crate.data.CollectionBucket)11 Bucket (io.crate.data.Bucket)10 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)10 InputColumn (io.crate.expression.symbol.InputColumn)6 BatchSimulatingIterator (io.crate.testing.BatchSimulatingIterator)6 ArrayBucket (io.crate.data.ArrayBucket)5 TestingHelpers.isRow (io.crate.testing.TestingHelpers.isRow)5 Streamer (io.crate.Streamer)4 Projector (io.crate.data.Projector)4 GroupingProjector (io.crate.execution.engine.aggregation.GroupingProjector)4 SortingProjector (io.crate.execution.engine.sort.SortingProjector)4 SortingTopNProjector (io.crate.execution.engine.sort.SortingTopNProjector)4 DistResultRXTask (io.crate.execution.jobs.DistResultRXTask)4 ArrayList (java.util.ArrayList)4 RowAccounting (io.crate.breaker.RowAccounting)3 CombinedRow (io.crate.data.join.CombinedRow)3 CompletionException (java.util.concurrent.CompletionException)3