Search in sources :

Example 1 with AggregationFunction

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);
}
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 AggregationFunction

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;
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) AggregationFunction(io.crate.operation.aggregation.AggregationFunction) ArrayList(java.util.ArrayList)

Example 3 with AggregationFunction

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);
}
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 4 with AggregationFunction

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);
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) FunctionIdent(io.crate.metadata.FunctionIdent) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) AggregationTest(io.crate.operation.aggregation.AggregationTest)

Aggregations

AggregationFunction (io.crate.operation.aggregation.AggregationFunction)4 FunctionIdent (io.crate.metadata.FunctionIdent)3 Aggregation (io.crate.analyze.symbol.Aggregation)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 FunctionInfo (io.crate.metadata.FunctionInfo)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 CollectExpression (io.crate.operation.collect.CollectExpression)2 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)2 AggregationTest (io.crate.operation.aggregation.AggregationTest)1 MinimumAggregation (io.crate.operation.aggregation.impl.MinimumAggregation)1 SumAggregation (io.crate.operation.aggregation.impl.SumAggregation)1 ArrayList (java.util.ArrayList)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 Test (org.junit.Test)1