use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class LongAnyAggregationTest method testLongAnyCombiningBufferAggregator.
@Test
public void testLongAnyCombiningBufferAggregator() {
BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[longAnyAggFactory.getMaxIntermediateSizeWithNulls()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
Long result = (Long) agg.get(buffer, 0);
Assert.assertEquals(objects[0], result, 0.0001);
Assert.assertEquals(objects[0].longValue(), agg.getLong(buffer, 0));
Assert.assertEquals(objects[0], agg.getLong(buffer, 0), 0.0001);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class VarianceAggregatorFactoryUnitTest method factorizeBufferedForComplexShouldReturnObjectVectorAggregator.
@Test
public void factorizeBufferedForComplexShouldReturnObjectVectorAggregator() {
mockType(VarianceAggregatorFactory.TYPE);
BufferAggregator agg = target.factorizeBuffered(metricFactory);
Assert.assertNotNull(agg);
Assert.assertEquals(VarianceBufferAggregator.ObjectVarianceAggregator.class, agg.getClass());
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class ExpressionAggregationBenchmark method compute.
private double compute(final Function<ColumnSelectorFactory, BufferAggregator> aggregatorFactory) {
final QueryableIndexStorageAdapter adapter = new QueryableIndexStorageAdapter(index);
final Sequence<Cursor> cursors = adapter.makeCursors(null, index.getDataInterval(), VirtualColumns.EMPTY, Granularities.ALL, false, null);
final List<Double> results = cursors.map(cursor -> {
final BufferAggregator bufferAggregator = aggregatorFactory.apply(cursor.getColumnSelectorFactory());
bufferAggregator.init(aggregationBuffer, 0);
while (!cursor.isDone()) {
bufferAggregator.aggregate(aggregationBuffer, 0);
cursor.advance();
}
final Double dbl = (Double) bufferAggregator.get(aggregationBuffer, 0);
bufferAggregator.close();
return dbl;
}).toList();
return Iterables.getOnlyElement(results);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class DoubleLastAggregationTest method testDoubleLastCombiningBufferAggregator.
@Test
public void testDoubleLastCombiningBufferAggregator() {
BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[doubleLastAggFactory.getMaxIntermediateSizeWithNulls()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
Pair<Long, Double> result = (Pair<Long, Double>) agg.get(buffer, 0);
Pair<Long, Double> expected = (Pair<Long, Double>) pairs[2];
Assert.assertEquals(expected.lhs, result.lhs);
Assert.assertEquals(expected.rhs, result.rhs, 0.0001);
Assert.assertEquals(expected.rhs.longValue(), agg.getLong(buffer, 0));
Assert.assertEquals(expected.rhs, agg.getDouble(buffer, 0), 0.0001);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class DoubleLastAggregationTest method testDoubleLastBufferAggregatorWithTimeColumn.
@Test
public void testDoubleLastBufferAggregatorWithTimeColumn() {
BufferAggregator agg = new DoubleLastAggregatorFactory("billy", "nilly", "customTime").factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[doubleLastAggFactory.getMaxIntermediateSizeWithNulls()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
Pair<Long, Double> result = (Pair<Long, Double>) agg.get(buffer, 0);
Assert.assertEquals(customTimes[1], result.lhs.longValue());
Assert.assertEquals(doubles[1], result.rhs, 0.0001);
Assert.assertEquals((long) doubles[1], agg.getLong(buffer, 0));
Assert.assertEquals(doubles[1], agg.getDouble(buffer, 0), 0.0001);
}
Aggregations