use of io.crate.analyze.symbol.Aggregation in project crate by crate.
the class GroupingIntegerCollectorBenchmark method createGroupBySumCollector.
private GroupingCollector createGroupBySumCollector(Functions functions) {
InputCollectExpression keyInput = new InputCollectExpression(0);
List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput);
CollectExpression[] collectExpressions = new CollectExpression[] { keyInput };
FunctionIdent functionIdent = new FunctionIdent(SumAggregation.NAME, Arrays.asList(DataTypes.INTEGER));
FunctionInfo functionInfo = new FunctionInfo(functionIdent, DataTypes.INTEGER, FunctionInfo.Type.AGGREGATE);
AggregationFunction sumAgg = (AggregationFunction) functions.get(functionIdent);
Aggregation aggregation = Aggregation.finalAggregation(functionInfo, Arrays.asList(new InputColumn(0)), Aggregation.Step.ITER);
Aggregator[] aggregators = new Aggregator[] { new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, sumAgg, new Input[] { keyInput }) };
return GroupingCollector.singleKey(collectExpressions, aggregators, RAM_ACCOUNTING_CONTEXT, keyInputs.get(0), DataTypes.INTEGER);
}
use of io.crate.analyze.symbol.Aggregation in project crate by crate.
the class NestedLoopConsumerTest method testAggregationOnCrossJoin.
@Test
public void testAggregationOnCrossJoin() throws Exception {
NestedLoop nl = plan("select min(u1.name) from users u1, users u2");
NestedLoopPhase nlPhase = nl.nestedLoopPhase();
assertThat(nlPhase.projections(), contains(instanceOf(EvalProjection.class), instanceOf(AggregationProjection.class), instanceOf(EvalProjection.class)));
AggregationProjection aggregationProjection = (AggregationProjection) nlPhase.projections().get(1);
Aggregation minAgg = aggregationProjection.aggregations().get(0);
assertThat(minAgg.fromStep(), is(Aggregation.Step.ITER));
assertThat(minAgg.toStep(), is(Aggregation.Step.FINAL));
}
use of io.crate.analyze.symbol.Aggregation in project crate by crate.
the class GroupingBytesRefCollectorBenchmark method createGroupByMinBytesRefCollector.
private GroupingCollector createGroupByMinBytesRefCollector(Functions functions) {
InputCollectExpression keyInput = new InputCollectExpression(0);
List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput);
CollectExpression[] collectExpressions = new CollectExpression[] { keyInput };
FunctionIdent minBytesRefFuncIdent = new FunctionIdent(MinimumAggregation.NAME, Arrays.asList(DataTypes.STRING));
FunctionInfo minBytesRefFuncInfo = new FunctionInfo(minBytesRefFuncIdent, DataTypes.INTEGER, FunctionInfo.Type.AGGREGATE);
AggregationFunction minAgg = (AggregationFunction) functions.get(minBytesRefFuncIdent);
Aggregation aggregation = Aggregation.finalAggregation(minBytesRefFuncInfo, Arrays.asList(new InputColumn(0)), Aggregation.Step.ITER);
Aggregator[] aggregators = new Aggregator[] { new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, minAgg, new Input[] { keyInput }) };
return GroupingCollector.singleKey(collectExpressions, aggregators, RAM_ACCOUNTING_CONTEXT, keyInputs.get(0), DataTypes.STRING);
}
use of io.crate.analyze.symbol.Aggregation in project crate by crate.
the class GroupProjectionTest method testStreaming2.
@Test
public void testStreaming2() throws Exception {
Reference nameRef = createReference("name", DataTypes.STRING);
List<Symbol> keys = Collections.singletonList(nameRef);
List<Aggregation> aggregations = Collections.singletonList(Aggregation.finalAggregation(new FunctionInfo(new FunctionIdent(CountAggregation.NAME, ImmutableList.of()), DataTypes.LONG), ImmutableList.of(), Aggregation.Step.PARTIAL));
GroupProjection groupProjection = new GroupProjection(keys, aggregations, RowGranularity.CLUSTER);
BytesStreamOutput out = new BytesStreamOutput();
Projection.toStream(groupProjection, out);
StreamInput in = StreamInput.wrap(out.bytes());
GroupProjection p2 = (GroupProjection) Projection.fromStream(in);
assertThat(p2.keys().size(), is(1));
assertThat(p2.values().size(), is(1));
}
use of io.crate.analyze.symbol.Aggregation in project crate by crate.
the class GroupProjectionTest method testStreaming.
@Test
public void testStreaming() throws Exception {
ImmutableList<Symbol> keys = ImmutableList.of(createReference("foo", DataTypes.STRING), createReference("bar", DataTypes.SHORT));
ImmutableList<Aggregation> aggregations = ImmutableList.of();
GroupProjection p = new GroupProjection(keys, aggregations, RowGranularity.CLUSTER);
BytesStreamOutput out = new BytesStreamOutput();
Projection.toStream(p, out);
StreamInput in = StreamInput.wrap(out.bytes());
GroupProjection p2 = (GroupProjection) Projection.fromStream(in);
assertEquals(p, p2);
}
Aggregations