use of io.crate.operation.aggregation.AggregationFunction 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.operation.aggregation.AggregationFunction in project crate by crate.
the class ProjectionBuilder method getAggregations.
private ArrayList<Aggregation> getAggregations(Collection<Function> functions, Aggregation.Step fromStep, Aggregation.Step toStep, InputCreatingVisitor.Context context) {
ArrayList<Aggregation> aggregations = new ArrayList<>(functions.size());
for (Function function : functions) {
assert function.info().type() == FunctionInfo.Type.AGGREGATE : "function type must be " + FunctionInfo.Type.AGGREGATE;
Aggregation aggregation;
List<Symbol> aggregationInputs;
if (fromStep == Aggregation.Step.PARTIAL) {
aggregationInputs = ImmutableList.<Symbol>of(context.inputs.get(function));
} else {
// ITER means that there is no aggregation part upfront, therefore the input
// symbols need to be in arguments
aggregationInputs = inputVisitor.process(function.arguments(), context);
}
if (toStep == Aggregation.Step.PARTIAL) {
aggregation = Aggregation.partialAggregation(function.info(), ((AggregationFunction) this.functions.get(function.info().ident())).partialType(), aggregationInputs);
} else {
aggregation = Aggregation.finalAggregation(function.info(), aggregationInputs, fromStep);
}
aggregations.add(aggregation);
}
return aggregations;
}
use of io.crate.operation.aggregation.AggregationFunction 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.operation.aggregation.AggregationFunction in project crate by crate.
the class CollectSetAggregationTest method testLongSerialization.
@Test
public void testLongSerialization() throws Exception {
FunctionIdent fi = new FunctionIdent("collect_set", ImmutableList.<DataType>of(DataTypes.LONG));
AggregationFunction impl = (AggregationFunction) functions.get(fi);
Object state = impl.newState(ramAccountingContext);
BytesStreamOutput streamOutput = new BytesStreamOutput();
impl.partialType().streamer().writeValueTo(streamOutput, state);
Object newState = impl.partialType().streamer().readValueFrom(StreamInput.wrap(streamOutput.bytes()));
assertEquals(state, newState);
}
Aggregations