use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class ProjectionToProjectorVisitorTest method testAggregationProjector.
@Test
public void testAggregationProjector() throws Exception {
AggregationProjection projection = new AggregationProjection(Arrays.asList(new Aggregation(avgSignature, avgSignature.getReturnType().createType(), Collections.singletonList(new InputColumn(1))), new Aggregation(CountAggregation.SIGNATURE, CountAggregation.SIGNATURE.getReturnType().createType(), Collections.singletonList(new InputColumn(0)))), RowGranularity.SHARD, AggregateMode.ITER_FINAL);
Projector projector = visitor.create(projection, txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, UUID.randomUUID());
assertThat(projector, instanceOf(AggregationPipe.class));
BatchIterator<Row> batchIterator = projector.apply(InMemoryBatchIterator.of(new CollectionBucket(Arrays.asList($("foo", 10), $("bar", 20))), SENTINEL, true));
TestingRowConsumer consumer = new TestingRowConsumer();
consumer.accept(batchIterator, null);
Bucket rows = consumer.getBucket();
assertThat(rows.size(), is(1));
assertThat(rows, contains(isRow(15.0, 2L)));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class ReaderBucketsTest method test_reader_bucket_accounts_memory_for_added_rows.
@Test
public void test_reader_bucket_accounts_memory_for_added_rows() throws Exception {
var e = SQLExecutor.builder(clusterService).addTable("create table t1 (x text)").build();
var t1 = e.resolveTableInfo("t1");
var x = (Reference) e.asSymbol("x");
var fetchSource = new FetchSource();
fetchSource.addFetchIdColumn(new InputColumn(0, DataTypes.LONG));
fetchSource.addRefToFetch(x);
var fetchRows = FetchRows.create(CoordinatorTxnCtx.systemTransactionContext(), TestingHelpers.createNodeContext(), Map.of(t1.ident(), fetchSource), List.of(new FetchReference(new InputColumn(0, DataTypes.LONG), x), new InputColumn(1, DataTypes.INTEGER)));
var bytesAccounted = new AtomicLong();
var ramAccounting = new BlockBasedRamAccounting(bytes -> bytesAccounted.addAndGet(bytes), 1024);
int readerId = 1;
var readerBuckets = new ReaderBuckets(fetchRows, reader -> fetchSource, new EstimateCellsSize(List.of(DataTypes.LONG, DataTypes.INTEGER)), ramAccounting);
long fetchId = FetchId.encode(readerId, 1);
readerBuckets.add(new RowN(fetchId, 42));
assertThat(bytesAccounted.get(), is(1024L));
assertThat(readerBuckets.ramBytesUsed(), is(40L));
IntObjectHashMap<Bucket> bucketsByReader = new IntObjectHashMap<>();
bucketsByReader.put(readerId, new CollectionBucket(List.<Object[]>of(new Object[] { "I eat memory for breakfast" })));
IntHashSet readerIds = new IntHashSet(2);
readerIds.add(readerId);
readerBuckets.generateToFetch(readerIds);
try (var outputRows = readerBuckets.getOutputRows(List.of(bucketsByReader))) {
assertThat(bytesAccounted.get(), is(1024L));
assertThat(readerBuckets.ramBytesUsed(), is(136L));
}
assertThat("After outputRows are closed the readerBuckets are released", readerBuckets.ramBytesUsed(), is(0L));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class ProjectingRowConsumerTest method testErrorHandlingIfProjectorApplicationFails.
@Test
public void testErrorHandlingIfProjectorApplicationFails() throws Exception {
WriterProjection writerProjection = new WriterProjection(Collections.singletonList(new InputColumn(0, DataTypes.STRING)), Literal.of("/x/y/z/hopefully/invalid/on/your/system/"), null, Collections.emptyMap(), Collections.emptyList(), WriterProjection.OutputFormat.JSON_OBJECT, Settings.EMPTY);
TestingRowConsumer consumer = new TestingRowConsumer();
RowConsumer rowConsumer = ProjectingRowConsumer.create(consumer, Collections.singletonList(writerProjection), UUID.randomUUID(), txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, projectorFactory);
rowConsumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
expectedException.expect(UnhandledServerException.class);
expectedException.expectMessage("Failed to open output");
consumer.getResult();
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class ProjectingRowConsumerTest method testConsumerRequiresScrollAndProjectorsDontSupportScrolling.
@Test
public void testConsumerRequiresScrollAndProjectorsDontSupportScrolling() {
List<Symbol> arguments = Arrays.asList(Literal.of(2), new InputColumn(1, DataTypes.INTEGER));
EqOperator op = (EqOperator) nodeCtx.functions().get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
Function function = new Function(op.signature(), arguments, EqOperator.RETURN_TYPE);
FilterProjection filterProjection = new FilterProjection(function, Arrays.asList(new InputColumn(0), new InputColumn(1)));
RowConsumer delegateConsumerRequiresScroll = new DummyRowConsumer(true);
RowConsumer projectingConsumer = ProjectingRowConsumer.create(delegateConsumerRequiresScroll, Collections.singletonList(filterProjection), UUID.randomUUID(), txnCtx, RamAccounting.NO_ACCOUNTING, memoryManager, projectorFactory);
assertThat(projectingConsumer.requiresScroll(), is(true));
}
use of io.crate.expression.symbol.InputColumn in project crate by crate.
the class InputFactoryTest method testProcessGroupByProjectionSymbolsAggregation.
@Test
public void testProcessGroupByProjectionSymbolsAggregation() throws Exception {
// select count(x), x, y * 2 ... group by x, y * 2
// keys: [ in(0), in(1) + 10 ]
List<Symbol> keys = Arrays.asList(new InputColumn(0, DataTypes.LONG), add);
Function countX = (Function) expressions.asSymbol("count(x)");
// values: [ count(in(0)) ]
List<Aggregation> values = List.of(new Aggregation(countX.signature(), countX.valueType(), List.of(new InputColumn(0))));
InputFactory.Context<CollectExpression<Row, ?>> ctx = factory.ctxForAggregations(txnCtx);
ctx.add(keys);
// inputs: [ x, add ]
List<Input<?>> keyInputs = ctx.topLevelInputs();
ctx.add(values);
List<AggregationContext> aggregations = ctx.aggregations();
assertThat(aggregations.size(), is(1));
// collectExpressions: [ in0, in1 ]
List<CollectExpression<Row, ?>> expressions = new ArrayList<>(ctx.expressions());
assertThat(expressions.size(), is(2));
List<Input<?>> allInputs = ctx.topLevelInputs();
// only 2 because count is no input
assertThat(allInputs.size(), is(2));
RowN row = new RowN(1L, 2L);
for (CollectExpression<Row, ?> expression : expressions) {
expression.setNextRow(row);
}
assertThat(expressions.get(0).value(), is(1L));
// raw input value
assertThat(expressions.get(1).value(), is(2L));
assertThat(keyInputs.size(), is(2));
assertThat(keyInputs.get(0).value(), is(1L));
// 2 + 10
assertThat(keyInputs.get(1).value(), is(12));
}
Aggregations