use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class ProjectionToProjectorVisitorTest method testGroupProjector.
@Test
public void testGroupProjector() throws Exception {
// in(0) in(1) in(0), in(2)
// select race, avg(age), count(race), gender ... group by race, gender
List<Symbol> keys = Arrays.asList(new InputColumn(0, DataTypes.STRING), new InputColumn(2, DataTypes.STRING));
List<Aggregation> aggregations = 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))));
GroupProjection projection = new GroupProjection(keys, aggregations, AggregateMode.ITER_FINAL, RowGranularity.CLUSTER);
Projector projector = visitor.create(projection, txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, UUID.randomUUID());
assertThat(projector, instanceOf(GroupingProjector.class));
// use a topN projection in order to get sorted outputs
List<Symbol> outputs = Arrays.asList(new InputColumn(0, DataTypes.STRING), new InputColumn(1, DataTypes.STRING), new InputColumn(2, DataTypes.DOUBLE), new InputColumn(3, DataTypes.LONG));
OrderedTopNProjection topNProjection = new OrderedTopNProjection(10, 0, outputs, List.of(new InputColumn(2, DataTypes.DOUBLE)), new boolean[] { false }, new boolean[] { false });
Projector topNProjector = visitor.create(topNProjection, txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, UUID.randomUUID());
String human = "human";
String vogon = "vogon";
String male = "male";
String female = "female";
List<Object[]> rows = new ArrayList<>();
rows.add($(human, 34, male));
rows.add($(human, 22, female));
rows.add($(vogon, 40, male));
rows.add($(vogon, 48, male));
rows.add($(human, 34, male));
BatchIterator<Row> batchIterator = topNProjector.apply(projector.apply(InMemoryBatchIterator.of(new CollectionBucket(rows), SENTINEL, true)));
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(batchIterator, null);
Bucket bucket = consumer.getBucket();
assertThat(bucket, contains(isRow(human, female, 22.0, 1L), isRow(human, male, 34.0, 2L), isRow(vogon, male, 44.0, 2L)));
}
use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class ProjectionToProjectorVisitorTest method testSimpleTopNProjection.
@Test
public void testSimpleTopNProjection() throws Exception {
TopNProjection projection = new TopNProjection(10, 2, Collections.singletonList(DataTypes.LONG));
Projector projector = visitor.create(projection, txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, UUID.randomUUID());
assertThat(projector, instanceOf(SimpleTopNProjector.class));
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(projector.apply(TestingBatchIterators.range(0, 20)), null);
List<Object[]> result = consumer.getResult();
assertThat(result.size(), is(10));
assertThat(result.get(0), is(new Object[] { 2 }));
}
use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class DependencyCarrierDDLTest method executePlan.
private Bucket executePlan(Plan plan, PlannerContext plannerContext, Row params) throws Exception {
TestingRowConsumer consumer = new TestingRowConsumer();
plan.execute(executor, plannerContext, consumer, params, SubQueryResults.EMPTY);
return consumer.getBucket();
}
use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class DistResultRXTaskTest method testKillCallsDownstream.
@Test
public void testKillCallsDownstream() throws Throwable {
TestingRowConsumer batchConsumer = new TestingRowConsumer();
DistResultRXTask ctx = getPageDownstreamContext(batchConsumer, PassThroughPagingIterator.oneShot(), 3);
final AtomicReference<Throwable> throwable = new AtomicReference<>();
ctx.completionFuture().whenComplete((r, t) -> {
if (t != null) {
assertTrue(throwable.compareAndSet(null, t));
} else {
fail("Expected exception");
}
});
ctx.kill(new InterruptedException());
assertThat(throwable.get(), instanceOf(CompletionException.class));
expectedException.expect(InterruptedException.class);
batchConsumer.getResult();
}
use of io.crate.testing.TestingRowConsumer in project crate by crate.
the class DistResultRXTaskTest method testCantSetSameBucketTwiceWithoutReceivingFullPage.
@Test
public void testCantSetSameBucketTwiceWithoutReceivingFullPage() throws Throwable {
TestingRowConsumer batchConsumer = new TestingRowConsumer();
DistResultRXTask ctx = getPageDownstreamContext(batchConsumer, PassThroughPagingIterator.oneShot(), 3);
PageResultListener pageResultListener = mock(PageResultListener.class);
Bucket bucket = new CollectionBucket(Collections.singletonList(new Object[] { "foo" }));
PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
assertThat(bucketReceiver, notNullValue());
bucketReceiver.setBucket(1, bucket, false, pageResultListener);
bucketReceiver.setBucket(1, bucket, false, pageResultListener);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Same bucket of a page set more than once. node=n1 method=setBucket phaseId=1 bucket=1");
batchConsumer.getResult();
}
Aggregations