Search in sources :

Example 1 with ArrayBucket

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

the class SortedPagingIteratorTest method testReplayReplaysCorrectly.

@Test
public void testReplayReplaysCorrectly() throws Exception {
    SortedPagingIterator<Void, Row> pagingIterator = new SortedPagingIterator<>(ORDERING, true);
    pagingIterator.merge(numberedBuckets(Arrays.<Bucket>asList(new ArrayBucket(new Object[][] { new Object[] { "a" }, new Object[] { "b" }, new Object[] { "c" } }), new ArrayBucket(new Object[][] { new Object[] { "x" }, new Object[] { "y" } }), new ArrayBucket(new Object[][] { new Object[] { "m" }, new Object[] { "n" }, new Object[] { "o" } }))));
    List<Object> rows = new ArrayList<>();
    consumeSingleColumnRows(pagingIterator, rows);
    pagingIterator.merge(numberedBuckets(Arrays.<Bucket>asList(new ArrayBucket(new Object[][] { new Object[] { "d" }, new Object[] { "e" }, new Object[] { "f" } }), new ArrayBucket(new Object[][] { new Object[] { "z" } }))));
    pagingIterator.finish();
    consumeSingleColumnRows(pagingIterator, rows);
    assertThat(rows.toString(), is("[a, b, c, d, e, f, m, n, o, x, y, z]"));
    List<Object> replayedRows = new ArrayList<>();
    consumeSingleColumnRows(pagingIterator.repeat().iterator(), replayedRows);
    assertThat(rows, is(replayedRows));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) Bucket(io.crate.data.Bucket) ArrayBucket(io.crate.data.ArrayBucket) ArrayList(java.util.ArrayList) Row(io.crate.data.Row) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with ArrayBucket

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

the class AggregationTest method executeAggregation.

public Object[][] executeAggregation(String name, DataType dataType, Object[][] data, List<DataType> argumentTypes) throws Exception {
    FunctionIdent fi;
    InputCollectExpression[] inputs;
    if (dataType != null) {
        fi = new FunctionIdent(name, argumentTypes);
        inputs = new InputCollectExpression[argumentTypes.size()];
        for (int i = 0; i < argumentTypes.size(); i++) {
            inputs[i] = new InputCollectExpression(i);
        }
    } else {
        fi = new FunctionIdent(name, ImmutableList.<DataType>of());
        inputs = new InputCollectExpression[0];
    }
    AggregationFunction impl = (AggregationFunction) functions.get(fi);
    Object state = impl.newState(ramAccountingContext);
    ArrayBucket bucket = new ArrayBucket(data);
    for (Row row : bucket) {
        for (InputCollectExpression i : inputs) {
            i.setNextRow(row);
        }
        state = impl.iterate(ramAccountingContext, state, inputs);
    }
    state = impl.terminatePartial(ramAccountingContext, state);
    return new Object[][] { { state } };
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) DataType(io.crate.types.DataType) Row(io.crate.data.Row)

Example 3 with ArrayBucket

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

the class DistributedResultRequestTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    Streamer<?>[] streamers = new Streamer[] { DataTypes.STRING.streamer() };
    Object[][] rows = new Object[][] { { new BytesRef("ab") }, { null }, { new BytesRef("cd") } };
    UUID uuid = UUID.randomUUID();
    DistributedResultRequest r1 = new DistributedResultRequest(uuid, 1, (byte) 3, 1, streamers, new ArrayBucket(rows), false);
    BytesStreamOutput out = new BytesStreamOutput();
    r1.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    DistributedResultRequest r2 = new DistributedResultRequest();
    r2.readFrom(in);
    r2.streamers(streamers);
    assertTrue(r2.rowsCanBeRead());
    assertEquals(r1.rows().size(), r2.rows().size());
    assertThat(r1.isLast(), is(r2.isLast()));
    assertThat(r1.executionPhaseInputId(), is(r2.executionPhaseInputId()));
    assertThat(r2.rows(), contains(isRow("ab"), isNullRow(), isRow("cd")));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) Streamer(io.crate.Streamer) DistributedResultRequest(io.crate.executor.transport.distributed.DistributedResultRequest) StreamInput(org.elasticsearch.common.io.stream.StreamInput) UUID(java.util.UUID) BytesRef(org.apache.lucene.util.BytesRef) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with ArrayBucket

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

the class DistResultRXTaskTest method testPagingWithSortedPagingIterator.

@Test
public void testPagingWithSortedPagingIterator() throws Throwable {
    TestingRowConsumer batchConsumer = new TestingRowConsumer();
    DistResultRXTask ctx = getPageDownstreamContext(batchConsumer, new SortedPagingIterator<>(Comparator.comparingInt(r -> (int) r.get(0)), false), 2);
    Bucket b1 = new ArrayBucket(new Object[][] { new Object[] { 1 }, new Object[] { 1 } });
    Bucket b11 = new ArrayBucket(new Object[][] { new Object[] { 2 }, new Object[] { 2 } });
    PageBucketReceiver bucketReceiver = ctx.getBucketReceiver((byte) 0);
    assertThat(bucketReceiver, notNullValue());
    bucketReceiver.setBucket(0, b1, false, needMore -> {
        if (needMore) {
            bucketReceiver.setBucket(0, b11, true, mock(PageResultListener.class));
        }
    });
    Bucket b2 = new ArrayBucket(new Object[][] { new Object[] { 4 } });
    bucketReceiver.setBucket(1, b2, true, mock(PageResultListener.class));
    List<Object[]> result = batchConsumer.getResult();
    assertThat(TestingHelpers.printedTable(new CollectionBucket(result)), is("1\n" + "1\n" + "2\n" + "2\n" + "4\n"));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) ArrayBucket(io.crate.data.ArrayBucket) TestingRowConsumer(io.crate.testing.TestingRowConsumer) CollectionBucket(io.crate.data.CollectionBucket) Test(org.junit.Test)

Example 5 with ArrayBucket

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

the class SortedPagingIteratorTest method testReplayReplaysCorrectly.

@Test
public void testReplayReplaysCorrectly() throws Exception {
    SortedPagingIterator<Void, Row> pagingIterator = new SortedPagingIterator<>(ORDERING, true);
    pagingIterator.merge(numberedBuckets(List.of(new ArrayBucket(new Object[][] { new Object[] { "a" }, new Object[] { "b" }, new Object[] { "c" } }), new ArrayBucket(new Object[][] { new Object[] { "x" }, new Object[] { "y" } }), new ArrayBucket(new Object[][] { new Object[] { "m" }, new Object[] { "n" }, new Object[] { "o" } }))));
    List<Object> rows = new ArrayList<>();
    consumeSingleColumnRows(pagingIterator, rows);
    pagingIterator.merge(numberedBuckets(List.of(new ArrayBucket(new Object[][] { new Object[] { "d" }, new Object[] { "e" }, new Object[] { "f" } }), new ArrayBucket(new Object[][] { new Object[] { "z" } }))));
    pagingIterator.finish();
    consumeSingleColumnRows(pagingIterator, rows);
    assertThat(rows.toString(), is("[a, b, c, d, e, f, m, n, o, x, y, z]"));
    List<Object> replayedRows = new ArrayList<>();
    consumeSingleColumnRows(pagingIterator.repeat().iterator(), replayedRows);
    assertThat(rows, is(replayedRows));
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) ArrayList(java.util.ArrayList) Row(io.crate.data.Row) Test(org.junit.Test)

Aggregations

ArrayBucket (io.crate.data.ArrayBucket)10 Test (org.junit.Test)9 Bucket (io.crate.data.Bucket)5 Row (io.crate.data.Row)5 CrateUnitTest (io.crate.test.integration.CrateUnitTest)4 ArrayList (java.util.ArrayList)4 CollectionBucket (io.crate.data.CollectionBucket)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)1 Streamer (io.crate.Streamer)1 RowN (io.crate.data.RowN)1 DistributedResultRequest (io.crate.executor.transport.distributed.DistributedResultRequest)1 FetchReference (io.crate.expression.symbol.FetchReference)1 InputColumn (io.crate.expression.symbol.InputColumn)1 FunctionIdent (io.crate.metadata.FunctionIdent)1 Reference (io.crate.metadata.Reference)1 PageResultListener (io.crate.operation.PageResultListener)1 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)1 FetchSource (io.crate.planner.node.fetch.FetchSource)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1