use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class LongFirstAggregationTest method testLongFirstCombiningBufferAggregator.
@Test
public void testLongFirstCombiningBufferAggregator() {
BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[longFirstAggFactory.getMaxIntermediateSizeWithNulls()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
Pair<Long, Long> result = (Pair<Long, Long>) agg.get(buffer, 0);
Pair<Long, Long> expected = (Pair<Long, Long>) pairs[0];
Assert.assertEquals(expected.lhs, result.lhs);
Assert.assertEquals(expected.rhs, result.rhs);
Assert.assertEquals(expected.rhs.longValue(), agg.getLong(buffer, 0));
Assert.assertEquals(expected.rhs, agg.getFloat(buffer, 0), 0.0001);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class LongFirstAggregationTest method testLongFirstBufferAggregatorWithTimeColumn.
@Test
public void testLongFirstBufferAggregatorWithTimeColumn() {
BufferAggregator agg = longFirstAggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[longFirstAggFactory.getMaxIntermediateSizeWithNulls()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
Pair<Long, Long> result = (Pair<Long, Long>) agg.get(buffer, 0);
Assert.assertEquals(times[3], result.lhs.longValue());
Assert.assertEquals(longValues[3], result.rhs.longValue());
Assert.assertEquals(longValues[3], agg.getLong(buffer, 0));
Assert.assertEquals(longValues[3], agg.getFloat(buffer, 0), 0.0001);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class FloatFirstAggregationTest method testFloatFirstBufferAggregatorWithTimeColumn.
@Test
public void testFloatFirstBufferAggregatorWithTimeColumn() {
BufferAggregator agg = new FloatFirstAggregatorFactory("billy", "nilly", "customTime").factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[floatFirstAggregatorFactory.getMaxIntermediateSizeWithNulls()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
Pair<Long, Float> result = (Pair<Long, Float>) agg.get(buffer, 0);
Assert.assertEquals(customTimes[1], result.lhs.longValue());
Assert.assertEquals(floats[1], result.rhs, 0.0001);
Assert.assertEquals((long) floats[1], agg.getLong(buffer, 0));
Assert.assertEquals(floats[1], agg.getFloat(buffer, 0), 0.0001);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class StringFirstAggregationTest method testStringFirstCombiningBufferAggregator.
@Test
public void testStringFirstCombiningBufferAggregator() {
BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[stringFirstAggFactory.getMaxIntermediateSize()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
Pair<Long, String> result = (Pair<Long, String>) agg.get(buffer, 0);
Pair<Long, String> expected = pairs[3];
Assert.assertEquals(expected.lhs, result.lhs);
Assert.assertEquals(expected.rhs, result.rhs);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class PooledTopNAlgorithm method computeSpecializedScanAndAggregateImplementations.
private static void computeSpecializedScanAndAggregateImplementations() {
SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.clear();
// The order of the following `if` blocks matters, "more specialized" implementations go first
if (SPECIALIZE_HISTORICAL_SINGLE_VALUE_DIM_SELECTOR_ONE_SIMPLE_DOUBLE_AGG_POOLED_TOPN) {
SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
if (theAggregators.length == 1) {
BufferAggregator aggregator = theAggregators[0];
final Cursor cursor = params.getCursor();
if (cursor instanceof HistoricalCursor && // doesn't clone offset anymore.
!(((HistoricalCursor) cursor).getOffset() instanceof FilteredOffset) && aggregator instanceof SimpleDoubleBufferAggregator && params.getDimSelector() instanceof SingleValueHistoricalDimensionSelector && ((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalColumnSelector) {
return scanAndAggregateHistorical1SimpleDoubleAgg(params, positions, (SimpleDoubleBufferAggregator) aggregator, (HistoricalCursor) cursor, DEFAULT_HISTORICAL_SINGLE_VALUE_DIM_SELECTOR_ONE_SIMPLE_DOUBLE_AGG_SCANNER);
}
}
return -1;
});
}
if (SPECIALIZE_HISTORICAL_ONE_SIMPLE_DOUBLE_AGG_POOLED_TOPN) {
SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
if (theAggregators.length == 1) {
BufferAggregator aggregator = theAggregators[0];
final Cursor cursor = params.getCursor();
if (cursor instanceof HistoricalCursor && // doesn't clone offset anymore.
!(((HistoricalCursor) cursor).getOffset() instanceof FilteredOffset) && aggregator instanceof SimpleDoubleBufferAggregator && params.getDimSelector() instanceof HistoricalDimensionSelector && ((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalColumnSelector) {
return scanAndAggregateHistorical1SimpleDoubleAgg(params, positions, (SimpleDoubleBufferAggregator) aggregator, (HistoricalCursor) cursor, DEFAULT_HISTORICAL_ONE_SIMPLE_DOUBLE_AGG_SCANNER);
}
}
return -1;
});
}
if (SPECIALIZE_GENERIC_ONE_AGG_POOLED_TOPN) {
SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
if (theAggregators.length == 1) {
return scanAndAggregateGeneric1Agg(params, positions, theAggregators[0], params.getCursor());
}
return -1;
});
}
if (SPECIALIZE_GENERIC_TWO_AGG_POOLED_TOPN) {
SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
if (theAggregators.length == 2) {
return scanAndAggregateGeneric2Agg(params, positions, theAggregators, params.getCursor());
}
return -1;
});
}
}
Aggregations