Search in sources :

Example 1 with Aggregation

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

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));
}
Also used : Aggregation(io.crate.analyze.symbol.Aggregation) NestedLoop(io.crate.planner.node.dql.join.NestedLoop) NestedLoopPhase(io.crate.planner.node.dql.join.NestedLoopPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with Aggregation

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

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));
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) FunctionIdent(io.crate.metadata.FunctionIdent) TestingHelpers.createReference(io.crate.testing.TestingHelpers.createReference) Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) FunctionInfo(io.crate.metadata.FunctionInfo) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with Aggregation

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);
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) Symbol(io.crate.analyze.symbol.Symbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Aggregation (io.crate.analyze.symbol.Aggregation)9 CrateUnitTest (io.crate.test.integration.CrateUnitTest)7 Test (org.junit.Test)7 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)6 InputColumn (io.crate.analyze.symbol.InputColumn)4 Symbol (io.crate.analyze.symbol.Symbol)4 FunctionIdent (io.crate.metadata.FunctionIdent)4 FunctionInfo (io.crate.metadata.FunctionInfo)4 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 StreamInput (org.elasticsearch.common.io.stream.StreamInput)4 Input (io.crate.data.Input)2 Reference (io.crate.metadata.Reference)2 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)2 Aggregator (io.crate.operation.aggregation.Aggregator)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 MergePhase (io.crate.planner.node.dql.MergePhase)1 NestedLoop (io.crate.planner.node.dql.join.NestedLoop)1