use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class BaseTopNAlgorithm method makeAggregators.
public static Aggregator[] makeAggregators(Cursor cursor, List<AggregatorFactory> aggregatorSpecs) {
Aggregator[] aggregators = new Aggregator[aggregatorSpecs.size()];
int aggregatorIndex = 0;
for (AggregatorFactory spec : aggregatorSpecs) {
aggregators[aggregatorIndex] = spec.factorize(cursor.getColumnSelectorFactory());
++aggregatorIndex;
}
return aggregators;
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class NullableNumericTopNColumnAggregatesProcessor method scanAndAggregate.
@Override
public long scanAndAggregate(TopNQuery query, Selector selector, Cursor cursor, Aggregator[][] rowSelector) {
long processedRows = 0;
while (!cursor.isDone()) {
if (hasNulls && selector.isNull()) {
if (nullValueAggregates == null) {
nullValueAggregates = BaseTopNAlgorithm.makeAggregators(cursor, query.getAggregatorSpecs());
}
for (Aggregator aggregator : nullValueAggregates) {
aggregator.aggregate();
}
} else {
Aggregator[] valueAggregates = getValueAggregators(query, selector, cursor);
for (Aggregator aggregator : valueAggregates) {
aggregator.aggregate();
}
}
cursor.advance();
processedRows++;
}
return processedRows;
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class LongLastAggregationTest method testLongLastCombiningAggregator.
@Test
public void testLongLastCombiningAggregator() {
Aggregator agg = combiningAggFactory.factorize(colSelectorFactory);
aggregate(agg);
aggregate(agg);
aggregate(agg);
aggregate(agg);
Pair<Long, Long> result = (Pair<Long, Long>) agg.get();
Pair<Long, Long> expected = (Pair<Long, Long>) pairs[2];
Assert.assertEquals(expected.lhs, result.lhs);
Assert.assertEquals(expected.rhs, result.rhs);
Assert.assertEquals(expected.rhs.longValue(), agg.getLong());
Assert.assertEquals(expected.rhs, agg.getFloat(), 1);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class DoubleMeanAggregationTest method testAggregateWithSize.
@Test
public void testAggregateWithSize() {
Double[] values = new Double[] { 3.0, 1.0, 2.0 };
TestObjectColumnSelector<Double> columnValueSelector = new TestObjectColumnSelector<>(values);
ColumnSelectorFactory colSelectorFactory = EasyMock.mock(ColumnSelectorFactory.class);
EasyMock.expect(colSelectorFactory.makeColumnValueSelector(EasyMock.anyString())).andReturn(columnValueSelector).anyTimes();
EasyMock.replay(colSelectorFactory);
DoubleMeanAggregatorFactory aggregatorFactory = new DoubleMeanAggregatorFactory("name", "fieldName");
AggregatorAndSize aggregatorAndSize = aggregatorFactory.factorizeWithSize(colSelectorFactory);
Assert.assertEquals(aggregatorFactory.getMaxIntermediateSize(), aggregatorAndSize.getInitialSizeBytes());
Assert.assertTrue(aggregatorAndSize.getAggregator() instanceof DoubleMeanAggregator);
Aggregator aggregator = aggregatorAndSize.getAggregator();
for (int i = 0; i < values.length; ++i) {
long sizeDelta = aggregator.aggregateWithSize();
Assert.assertEquals(0L, sizeDelta);
columnValueSelector.increment();
}
DoubleMeanHolder meanHolder = (DoubleMeanHolder) aggregator.get();
Assert.assertEquals(2.0, meanHolder.mean(), 0.0);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class FloatLastAggregationTest method testFloatLastAggregator.
@Test
public void testFloatLastAggregator() {
Aggregator agg = floatLastAggregatorFactory.factorize(colSelectorFactory);
aggregate(agg);
aggregate(agg);
aggregate(agg);
aggregate(agg);
Pair<Long, Float> result = (Pair<Long, Float>) agg.get();
Assert.assertEquals(times[0], result.lhs.longValue());
Assert.assertEquals(floats[0], result.rhs, 0.0001);
Assert.assertEquals((long) floats[0], agg.getLong());
Assert.assertEquals(floats[0], agg.getFloat(), 0.0001);
}
Aggregations