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));
}
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 } };
}
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")));
}
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"));
}
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));
}
Aggregations