Search in sources :

Example 1 with Aggregator

use of io.crate.operation.aggregation.Aggregator 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);
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) Aggregation(io.crate.analyze.symbol.Aggregation) SumAggregation(io.crate.operation.aggregation.impl.SumAggregation) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) InputColumn(io.crate.analyze.symbol.InputColumn) FunctionInfo(io.crate.metadata.FunctionInfo) Aggregator(io.crate.operation.aggregation.Aggregator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression)

Example 2 with Aggregator

use of io.crate.operation.aggregation.Aggregator 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);
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) Aggregation(io.crate.analyze.symbol.Aggregation) MinimumAggregation(io.crate.operation.aggregation.impl.MinimumAggregation) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) InputColumn(io.crate.analyze.symbol.InputColumn) FunctionInfo(io.crate.metadata.FunctionInfo) Aggregator(io.crate.operation.aggregation.Aggregator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression)

Example 3 with Aggregator

use of io.crate.operation.aggregation.Aggregator in project crate by crate.

the class GroupingCollector method addNewEntry.

private void addNewEntry(Map<K, Object[]> statesByKey, K key) {
    Object[] states;
    states = new Object[aggregators.length];
    for (int i = 0; i < aggregators.length; i++) {
        Aggregator aggregator = aggregators[i];
        states[i] = aggregator.processRow(aggregator.prepareState());
    }
    // key size + 32 bytes for entry + 4 bytes for increased capacity
    ramAccountingContext.addBytes(RamAccountingContext.roundUp(keySizeEstimator.estimateSize(key) + 36L));
    statesByKey.put(key, states);
}
Also used : Aggregator(io.crate.operation.aggregation.Aggregator)

Aggregations

Aggregator (io.crate.operation.aggregation.Aggregator)3 Aggregation (io.crate.analyze.symbol.Aggregation)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 FunctionIdent (io.crate.metadata.FunctionIdent)2 FunctionInfo (io.crate.metadata.FunctionInfo)2 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)2 CollectExpression (io.crate.operation.collect.CollectExpression)2 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)2 MinimumAggregation (io.crate.operation.aggregation.impl.MinimumAggregation)1 SumAggregation (io.crate.operation.aggregation.impl.SumAggregation)1