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);
}
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()));
}
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));
}
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));
}
Aggregations