Search in sources :

Example 11 with TestingRowConsumer

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

the class FileWriterProjectorTest method testDirectoryAsFile.

@Test
public void testDirectoryAsFile() throws Exception {
    expectedException.expect(UnhandledServerException.class);
    expectedException.expectMessage("Failed to open output: 'Output path is a directory: ");
    Path directory = createTempDir();
    FileWriterProjector fileWriterProjector = new FileWriterProjector(executorService, directory.toUri().toString(), null, null, Set.of(), new HashMap<>(), null, WriterProjection.OutputFormat.JSON_OBJECT, Map.of(LocalFsFileOutputFactory.NAME, new LocalFsFileOutputFactory()), Settings.EMPTY);
    new TestingRowConsumer().accept(fileWriterProjector.apply(sourceSupplier.get()), null);
}
Also used : Path(java.nio.file.Path) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 12 with TestingRowConsumer

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

the class FileWriterProjectorTest method testWriteRawToFile.

@Test
public void testWriteRawToFile() throws Exception {
    Path file = createTempFile("out", "json");
    FileWriterProjector fileWriterProjector = new FileWriterProjector(executorService, file.toUri().toString(), null, null, Set.of(), new HashMap<>(), null, WriterProjection.OutputFormat.JSON_OBJECT, Map.of(LocalFsFileOutputFactory.NAME, new LocalFsFileOutputFactory()), Settings.EMPTY);
    new TestingRowConsumer().accept(fileWriterProjector.apply(sourceSupplier.get()), null);
    assertEquals("input line 00\n" + "input line 01\n" + "input line 02\n" + "input line 03\n" + "input line 04", TestingHelpers.readFile(file.toAbsolutePath().toString()));
}
Also used : Path(java.nio.file.Path) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 13 with TestingRowConsumer

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

the class DocValuesGroupByOptimizedIteratorTest method test_group_by_doc_values_optimized_iterator_for_many_keys.

@Test
public void test_group_by_doc_values_optimized_iterator_for_many_keys() throws Exception {
    SumAggregation<?> sumAggregation = (SumAggregation<?>) functions.getQualified(Signature.aggregate(SumAggregation.NAME, DataTypes.LONG.getTypeSignature(), DataTypes.LONG.getTypeSignature()), List.of(DataTypes.LONG), DataTypes.LONG);
    var sumDocValuesAggregator = sumAggregation.getDocValueAggregator(List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "z"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 0, null)), mock(DocTableInfo.class), List.of());
    var keyExpressions = List.of(new BytesRefColumnReference("x"), new LongColumnReference("y"));
    var keyRefs = List.of(new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "x"), RowGranularity.DOC, DataTypes.STRING, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 1, null), new Reference(new ReferenceIdent(RelationName.fromIndexName("test"), "y"), RowGranularity.DOC, DataTypes.LONG, ColumnPolicy.DYNAMIC, IndexType.PLAIN, true, true, 2, null));
    var it = DocValuesGroupByOptimizedIterator.GroupByIterator.forManyKeys(List.of(sumDocValuesAggregator), indexSearcher, keyRefs, keyExpressions, RamAccounting.NO_ACCOUNTING, null, null, new MatchAllDocsQuery(), new CollectorContext());
    var rowConsumer = new TestingRowConsumer();
    rowConsumer.accept(it, null);
    assertThat(rowConsumer.getResult(), containsInAnyOrder(new Object[] { "0", 0L, 6L }, new Object[] { "1", 1L, 4L }));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) BytesRefColumnReference(io.crate.expression.reference.doc.lucene.BytesRefColumnReference) BytesRefColumnReference(io.crate.expression.reference.doc.lucene.BytesRefColumnReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) Reference(io.crate.metadata.Reference) SumAggregation(io.crate.execution.engine.aggregation.impl.SumAggregation) LongColumnReference(io.crate.expression.reference.doc.lucene.LongColumnReference) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ReferenceIdent(io.crate.metadata.ReferenceIdent) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 14 with TestingRowConsumer

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

the class CollectTaskTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    localNodeId = "dummyLocalNodeId";
    collectPhase = Mockito.mock(RoutedCollectPhase.class);
    Routing routing = Mockito.mock(Routing.class);
    when(routing.containsShards(localNodeId)).thenReturn(true);
    when(collectPhase.routing()).thenReturn(routing);
    when(collectPhase.maxRowGranularity()).thenReturn(RowGranularity.DOC);
    collectOperation = mock(MapSideDataCollectOperation.class);
    Mockito.doAnswer(new Answer<>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Runnable runnable = invocation.getArgument(0);
            runnable.run();
            return null;
        }
    }).when(collectOperation).launch(Mockito.any(), Mockito.anyString());
    consumer = new TestingRowConsumer();
    collectTask = new CollectTask(collectPhase, CoordinatorTxnCtx.systemTransactionContext(), collectOperation, RamAccounting.NO_ACCOUNTING, ramAccounting -> new OnHeapMemoryManager(ramAccounting::addBytes), consumer, mock(SharedShardContexts.class), Version.CURRENT, 4096);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) BatchIterator(io.crate.data.BatchIterator) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Routing(io.crate.metadata.Routing) SharedShardContexts(io.crate.execution.jobs.SharedShardContexts) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ESTestCase(org.elasticsearch.test.ESTestCase) Before(org.junit.Before) JobKilledException(io.crate.exceptions.JobKilledException) InMemoryBatchIterator(io.crate.data.InMemoryBatchIterator) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RamAccounting(io.crate.breaker.RamAccounting) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) Exceptions(io.crate.exceptions.Exceptions) Version(org.elasticsearch.Version) RowGranularity(io.crate.metadata.RowGranularity) Row(io.crate.data.Row) Matchers.is(org.hamcrest.Matchers.is) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) RefCountedItem(io.crate.common.collections.RefCountedItem) TestingRowConsumer(io.crate.testing.TestingRowConsumer) SentinelRow(io.crate.data.SentinelRow) Mockito.mock(org.mockito.Mockito.mock) IndexSearcher(org.apache.lucene.search.IndexSearcher) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) OnHeapMemoryManager(io.crate.memory.OnHeapMemoryManager) Routing(io.crate.metadata.Routing) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Before(org.junit.Before)

Example 15 with TestingRowConsumer

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

the class HashInnerJoinBatchIteratorBehaviouralTest method test_SwitchToRightWhenLeftExhausted.

@Test
public void test_SwitchToRightWhenLeftExhausted() throws Exception {
    BatchSimulatingIterator<Row> leftIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(1, 2, 3, 4)), 2, 1, null);
    BatchSimulatingIterator<Row> rightIterator = new BatchSimulatingIterator<>(TestingBatchIterators.ofValues(Arrays.asList(2, 0, 4, 5)), 2, 1, null);
    BatchIterator<Row> batchIterator = new HashInnerJoinBatchIterator(leftIterator, rightIterator, mock(RowAccounting.class), new CombinedRow(1, 1), row -> Objects.equals(row.get(0), row.get(1)), row -> Objects.hash(row.get(0)), row -> Objects.hash(row.get(0)), () -> 500000);
    TestingRowConsumer consumer = new TestingRowConsumer();
    consumer.accept(batchIterator, null);
    List<Object[]> result = consumer.getResult();
    assertThat(result, contains(new Object[] { 2, 2 }, new Object[] { 4, 4 }));
}
Also used : RowAccounting(io.crate.breaker.RowAccounting) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) Row(io.crate.data.Row) CombinedRow(io.crate.data.join.CombinedRow) CombinedRow(io.crate.data.join.CombinedRow) 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