Search in sources :

Example 26 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class SingleBucketBuilderTest method testSingleBucketBuilderWithBatchedSource.

@Test
public void testSingleBucketBuilderWithBatchedSource() throws Exception {
    BatchIterator iterator = TestingBatchIterators.range(0, 4);
    bucketBuilder.accept(new BatchSimulatingIterator(iterator, 2, 2, executor), null);
    Bucket rows = bucketBuilder.completionFuture().get(10, TimeUnit.SECONDS);
    assertThat(TestingHelpers.printedTable(rows), is("0\n" + "1\n" + "2\n" + "3\n"));
}
Also used : BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Bucket(io.crate.data.Bucket) BatchIterator(io.crate.data.BatchIterator) FailingBatchIterator(io.crate.testing.FailingBatchIterator) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 27 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class IndexWriterCountBatchIteratorTest method testIndexWriterIterator.

@Test
public void testIndexWriterIterator() throws Exception {
    execute("create table bulk_import (id int primary key) with (number_of_replicas=0)");
    ensureGreen();
    Supplier<BatchIterator> sourceSupplier = () -> RowsBatchIterator.newInstance(RowGenerator.fromSingleColValues(() -> IntStream.range(0, 10).mapToObj(i -> new BytesRef("{\"id\": " + i + "}")).iterator()), 1);
    Supplier<String> indexNameResolver = IndexNameResolver.forTable(new TableIdent(null, "bulk_import"));
    Input<?> sourceInput = new InputCollectExpression(0);
    List<CollectExpression<Row, ?>> collectExpressions = Collections.singletonList((InputCollectExpression) sourceInput);
    RowShardResolver rowShardResolver = getRowShardResolver();
    BulkShardProcessor bulkShardProcessor = getBulkShardProcessor();
    Supplier<ShardUpsertRequest.Item> updateItemSupplier = () -> new ShardUpsertRequest.Item(rowShardResolver.id(), null, new Object[] { sourceInput.value() }, null);
    List<Object[]> expectedResult = Collections.singletonList(new Object[] { 10L });
    BatchIteratorTester tester = new BatchIteratorTester(() -> IndexWriterCountBatchIterator.newIndexInstance(sourceSupplier.get(), indexNameResolver, collectExpressions, rowShardResolver, bulkShardProcessor, updateItemSupplier));
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : CrateSettings(io.crate.metadata.settings.CrateSettings) TransportBulkCreateIndicesAction(org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction) IntStream(java.util.stream.IntStream) Input(io.crate.data.Input) Arrays(java.util.Arrays) BulkShardProcessor(org.elasticsearch.action.bulk.BulkShardProcessor) InputColumn(io.crate.analyze.symbol.InputColumn) BatchIterator(io.crate.data.BatchIterator) BatchIteratorTester(io.crate.testing.BatchIteratorTester) Supplier(java.util.function.Supplier) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) CollectExpression(io.crate.operation.collect.CollectExpression) Settings(org.elasticsearch.common.settings.Settings) Symbol(io.crate.analyze.symbol.Symbol) ClusterService(org.elasticsearch.cluster.ClusterService) io.crate.metadata(io.crate.metadata) DocSysColumns(io.crate.metadata.doc.DocSysColumns) RowsBatchIterator(io.crate.data.RowsBatchIterator) RowShardResolver(io.crate.operation.collect.RowShardResolver) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) UUID(java.util.UUID) RowGenerator(io.crate.testing.RowGenerator) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) TransportShardUpsertAction(io.crate.executor.transport.TransportShardUpsertAction) List(java.util.List) Row(io.crate.data.Row) DataTypes(io.crate.types.DataTypes) BulkRetryCoordinatorPool(org.elasticsearch.action.bulk.BulkRetryCoordinatorPool) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) Collections(java.util.Collections) BatchIterator(io.crate.data.BatchIterator) RowsBatchIterator(io.crate.data.RowsBatchIterator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BulkShardProcessor(org.elasticsearch.action.bulk.BulkShardProcessor) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) BatchIteratorTester(io.crate.testing.BatchIteratorTester) BytesRef(org.apache.lucene.util.BytesRef) RowShardResolver(io.crate.operation.collect.RowShardResolver) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 28 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class SortingProjectorTest method testOrderBy.

@Test
public void testOrderBy() throws Exception {
    SortingProjector projector = createProjector(2, 0);
    BatchIterator batchIterator = projector.apply(TestingBatchIterators.range(1, 11));
    consumer.accept(batchIterator, null);
    Bucket rows = consumer.getBucket();
    assertThat(rows.size(), is(10));
    int iterateLength = 1;
    for (Row row : rows) {
        assertThat(row, isRow(iterateLength++, true));
    }
}
Also used : Bucket(io.crate.data.Bucket) BatchIterator(io.crate.data.BatchIterator) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) Row(io.crate.data.Row) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 29 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class SortingProjectorTest method testOrderByWithOffset.

@Test
public void testOrderByWithOffset() throws Exception {
    SortingProjector projector = createProjector(2, 5);
    BatchIterator batchIterator = projector.apply(TestingBatchIterators.range(1, 11));
    consumer.accept(batchIterator, null);
    Bucket rows = consumer.getBucket();
    assertThat(rows.size(), is(5));
    int iterateLength = 6;
    for (Row row : rows) {
        assertThat(row, isRow(iterateLength++, true));
    }
}
Also used : Bucket(io.crate.data.Bucket) BatchIterator(io.crate.data.BatchIterator) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) Row(io.crate.data.Row) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 30 with BatchIterator

use of io.crate.data.BatchIterator in project crate by crate.

the class NodeStatsIteratorTest method testRequestsAreIssued.

@Test
public void testRequestsAreIssued() throws InterruptedException, ExecutionException, TimeoutException {
    List<Symbol> toCollect = new ArrayList<>();
    toCollect.add(idRef);
    toCollect.add(nameRef);
    when(collectPhase.toCollect()).thenReturn(toCollect);
    BatchIterator iterator = NodeStatsIterator.newInstance(transportNodeStatsAction, collectPhase, nodes, new InputFactory(getFunctions()));
    iterator.loadNextBatch();
    verifyNoMoreInteractions(transportNodeStatsAction);
}
Also used : InputFactory(io.crate.operation.InputFactory) Symbol(io.crate.analyze.symbol.Symbol) BatchIterator(io.crate.data.BatchIterator) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

BatchIterator (io.crate.data.BatchIterator)50 Test (org.junit.Test)37 BatchIteratorTester (io.crate.testing.BatchIteratorTester)22 InMemoryBatchIterator (io.crate.data.InMemoryBatchIterator)17 Row (io.crate.data.Row)16 ArrayList (java.util.ArrayList)10 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 List (java.util.List)8 Map (java.util.Map)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 Bucket (io.crate.data.Bucket)6 InputFactory (io.crate.expression.InputFactory)6 Symbol (io.crate.analyze.symbol.Symbol)4 RowAccounting (io.crate.breaker.RowAccounting)4 RowN (io.crate.data.RowN)4 CombinedRow (io.crate.data.join.CombinedRow)4 InputFactory (io.crate.operation.InputFactory)4 TestingHelpers.isRow (io.crate.testing.TestingHelpers.isRow)4 UUID (java.util.UUID)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4