use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class IndexWriterProjectorUnitTest method testNullPKValue.
@Test
public void testNullPKValue() throws Throwable {
InputCollectExpression sourceInput = new InputCollectExpression(0);
List<CollectExpression<Row, ?>> collectExpressions = Collections.<CollectExpression<Row, ?>>singletonList(sourceInput);
final IndexWriterProjector indexWriter = new IndexWriterProjector(clusterService, TestingHelpers.getFunctions(), new IndexNameExpressionResolver(Settings.EMPTY), Settings.EMPTY, mock(TransportBulkCreateIndicesAction.class), mock(BulkRequestExecutor.class), () -> "foo", mock(BulkRetryCoordinatorPool.class, Answers.RETURNS_DEEP_STUBS.get()), rawSourceReference, ImmutableList.of(ID_IDENT), Arrays.<Symbol>asList(new InputColumn(1)), null, null, sourceInput, collectExpressions, 20, null, null, false, false, UUID.randomUUID());
RowN rowN = new RowN(new Object[] { new BytesRef("{\"y\": \"x\"}"), null });
BatchIterator batchIterator = RowsBatchIterator.newInstance(Collections.singletonList(rowN), rowN.numColumns());
batchIterator = indexWriter.apply(batchIterator);
TestingBatchConsumer testingBatchConsumer = new TestingBatchConsumer();
testingBatchConsumer.accept(batchIterator, null);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("A primary key value must not be NULL");
testingBatchConsumer.getResult();
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class ProjectionToProjectorVisitorTest method testFilterProjection.
@Test
public void testFilterProjection() throws Exception {
EqOperator op = (EqOperator) functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.of(DataTypes.INTEGER, DataTypes.INTEGER)));
Function function = new Function(op.info(), Arrays.asList(Literal.of(2), new InputColumn(1)));
FilterProjection projection = new FilterProjection(function, Arrays.asList(new InputColumn(0), new InputColumn(1)));
Projector projector = visitor.create(projection, RAM_ACCOUNTING_CONTEXT, UUID.randomUUID());
assertThat(projector, instanceOf(FilterProjector.class));
List<Object[]> rows = new ArrayList<>();
rows.add($("human", 2));
rows.add($("vogon", 1));
BatchIterator filteredBI = projector.apply(RowsBatchIterator.newInstance(new CollectionBucket(rows), 2));
TestingBatchConsumer consumer = new TestingBatchConsumer();
consumer.accept(filteredBI, null);
Bucket bucket = consumer.getBucket();
assertThat(bucket.size(), is(1));
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class ProjectionToProjectorVisitorTest method testAggregationProjector.
@Test
public void testAggregationProjector() throws Exception {
AggregationProjection projection = new AggregationProjection(Arrays.asList(Aggregation.finalAggregation(avgInfo, Collections.singletonList(new InputColumn(1)), Aggregation.Step.ITER), Aggregation.finalAggregation(countInfo, Collections.singletonList(new InputColumn(0)), Aggregation.Step.ITER)), RowGranularity.SHARD);
Projector projector = visitor.create(projection, RAM_ACCOUNTING_CONTEXT, UUID.randomUUID());
assertThat(projector, instanceOf(AggregationPipe.class));
BatchIterator batchIterator = projector.apply(RowsBatchIterator.newInstance(new CollectionBucket(Arrays.asList($("foo", 10), $("bar", 20))), 2));
TestingBatchConsumer consumer = new TestingBatchConsumer();
consumer.accept(batchIterator, null);
Bucket rows = consumer.getBucket();
assertThat(rows.size(), is(1));
assertThat(rows, contains(isRow(15.0, 2L)));
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class ProjectionToProjectorVisitorTest method testSimpleTopNProjection.
@Test
public void testSimpleTopNProjection() throws Exception {
List<Symbol> outputs = Arrays.asList(Literal.of("foo"), new InputColumn(0));
TopNProjection projection = new TopNProjection(10, 2, outputs);
Projector projector = visitor.create(projection, RAM_ACCOUNTING_CONTEXT, UUID.randomUUID());
assertThat(projector, instanceOf(SimpleTopNProjector.class));
TestingBatchConsumer consumer = new TestingBatchConsumer();
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[] { new BytesRef("foo"), 2 }));
}
use of io.crate.testing.TestingBatchConsumer in project crate by crate.
the class TransportExecutorDDLTest method testDeletePartitionTask.
@Test
public void testDeletePartitionTask() throws Exception {
execute("create table t (id integer primary key, name string) partitioned by (id)");
ensureYellow();
execute("insert into t (id, name) values (1, 'Ford')");
assertThat(response.rowCount(), is(1L));
ensureYellow();
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(1L));
String partitionName = new PartitionName("t", ImmutableList.of(new BytesRef("1"))).asIndexName();
ESDeletePartition plan = new ESDeletePartition(UUID.randomUUID(), partitionName);
TestingBatchConsumer consumer = new TestingBatchConsumer();
executor.execute(plan, consumer, Row.EMPTY);
Bucket objects = consumer.getBucket();
assertThat(objects, contains(isRow(-1L)));
execute("select * from information_schema.table_partitions where table_name = 't'");
assertThat(response.rowCount(), is(0L));
}
Aggregations