Search in sources :

Example 11 with TestingBatchConsumer

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();
}
Also used : BatchIterator(io.crate.data.BatchIterator) RowsBatchIterator(io.crate.data.RowsBatchIterator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkRetryCoordinatorPool(org.elasticsearch.action.bulk.BulkRetryCoordinatorPool) RowN(io.crate.data.RowN) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkRequestExecutor(org.elasticsearch.action.bulk.BulkRequestExecutor) InputColumn(io.crate.analyze.symbol.InputColumn) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportBulkCreateIndicesAction(org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 12 with TestingBatchConsumer

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));
}
Also used : EqOperator(io.crate.operation.operator.EqOperator) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with TestingBatchConsumer

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)));
}
Also used : TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 14 with TestingBatchConsumer

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 }));
}
Also used : TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with TestingBatchConsumer

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));
}
Also used : PartitionName(io.crate.metadata.PartitionName) Bucket(io.crate.data.Bucket) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) BytesRef(org.apache.lucene.util.BytesRef) ESDeletePartition(io.crate.planner.node.ddl.ESDeletePartition) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Aggregations

TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)47 Test (org.junit.Test)41 CrateUnitTest (io.crate.test.integration.CrateUnitTest)32 BytesRef (org.apache.lucene.util.BytesRef)7 CollectionBucket (io.crate.data.CollectionBucket)6 Bucket (io.crate.data.Bucket)4 PageResultListener (io.crate.operation.PageResultListener)4 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)4 Streamer (io.crate.Streamer)3 NestedLoopBatchIterator (io.crate.data.join.NestedLoopBatchIterator)3 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)3 Routing (io.crate.metadata.Routing)3 SharedShardContexts (io.crate.action.job.SharedShardContexts)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 ArrayBucket (io.crate.data.ArrayBucket)2 BatchConsumer (io.crate.data.BatchConsumer)2 CompositeBatchIterator (io.crate.data.CompositeBatchIterator)2 PageDownstreamContext (io.crate.jobs.PageDownstreamContext)2 PartitionName (io.crate.metadata.PartitionName)2 CollectExpression (io.crate.operation.collect.CollectExpression)2