Search in sources :

Example 6 with Aggregation

use of io.crate.analyze.symbol.Aggregation in project crate by crate.

the class GroupProjectionTest method testStreamingGranularity.

@Test
public void testStreamingGranularity() 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.SHARD);
    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)

Example 7 with Aggregation

use of io.crate.analyze.symbol.Aggregation in project crate by crate.

the class MergeNodeTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Reference nameRef = TestingHelpers.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);
    TopNProjection topNProjection = new TopNProjection(10, 0, InputColumn.numInputs(keys.size() + aggregations.size()));
    List<Projection> projections = Arrays.asList(groupProjection, topNProjection);
    MergePhase node = new MergePhase(UUID.randomUUID(), 0, "merge", 2, Collections.emptyList(), Arrays.<DataType>asList(DataTypes.UNDEFINED, DataTypes.STRING), projections, DistributionInfo.DEFAULT_BROADCAST, null);
    node.executionNodes(Sets.newHashSet("node1", "node2"));
    BytesStreamOutput output = new BytesStreamOutput();
    node.writeTo(output);
    StreamInput input = StreamInput.wrap(output.bytes());
    MergePhase node2 = MergePhase.FACTORY.create();
    node2.readFrom(input);
    assertThat(node.numUpstreams(), is(node2.numUpstreams()));
    assertThat(node.nodeIds(), is(node2.nodeIds()));
    assertThat(node.jobId(), is(node2.jobId()));
    assertEquals(node.inputTypes(), node2.inputTypes());
    assertThat(node.phaseId(), is(node2.phaseId()));
    assertThat(node.distributionInfo(), is(node2.distributionInfo()));
}
Also used : Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) FunctionInfo(io.crate.metadata.FunctionInfo) TopNProjection(io.crate.planner.projection.TopNProjection) GroupProjection(io.crate.planner.projection.GroupProjection) Projection(io.crate.planner.projection.Projection) TopNProjection(io.crate.planner.projection.TopNProjection) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) FunctionIdent(io.crate.metadata.FunctionIdent) MergePhase(io.crate.planner.node.dql.MergePhase) StreamInput(org.elasticsearch.common.io.stream.StreamInput) GroupProjection(io.crate.planner.projection.GroupProjection) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with Aggregation

use of io.crate.analyze.symbol.Aggregation in project crate by crate.

the class AggregatorTest method testAggregationFromPartial.

@Test
public void testAggregationFromPartial() {
    Aggregation aggregation = Aggregation.finalAggregation(countImpl.info(), Collections.<Symbol>singletonList(new InputColumn(0)), Aggregation.Step.PARTIAL);
    Input dummyInput = new Input() {

        CountAggregation.LongState state = new CountAggregation.LongState(10L);

        @Override
        public Object value() {
            return state;
        }
    };
    Aggregator aggregator = new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, countImpl, dummyInput);
    Object state = aggregator.prepareState();
    state = aggregator.processRow(state);
    state = aggregator.processRow(state);
    Object result = aggregator.finishCollect(state);
    assertThat((Long) result, is(20L));
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) Input(io.crate.data.Input) InputColumn(io.crate.analyze.symbol.InputColumn) CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with Aggregation

use of io.crate.analyze.symbol.Aggregation in project crate by crate.

the class AggregatorTest method testAggregationFromIterToFinal.

@Test
public void testAggregationFromIterToFinal() {
    Aggregation aggregation = Aggregation.finalAggregation(countImpl.info(), Collections.<Symbol>singletonList(new InputColumn(0)), Aggregation.Step.ITER);
    Input dummyInput = new Input() {

        @Override
        public Object value() {
            return 300L;
        }
    };
    Aggregator collector = new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, countImpl, dummyInput);
    Object state = collector.prepareState();
    for (int i = 0; i < 5; i++) {
        state = collector.processRow(state);
    }
    long result = (Long) collector.finishCollect(state);
    assertThat(result, is(5L));
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) Input(io.crate.data.Input) InputColumn(io.crate.analyze.symbol.InputColumn) 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