use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class StringFirstAggregationTest method testStringFirstBufferAggregator.
@Test
public void testStringFirstBufferAggregator() {
BufferAggregator agg = new StringFirstAggregatorFactory("billy", "nilly", "customTime", MAX_STRING_SIZE).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);
Assert.assertEquals(strings[1], result.rhs);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class StringAnyAggregationTest method testStringAnyCombiningBufferAggregator.
@Test
public void testStringAnyCombiningBufferAggregator() {
BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[stringAnyAggFactory.getMaxIntermediateSize()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
String result = (String) agg.get(buffer, 0);
Assert.assertEquals(strings[0], result);
Assert.assertEquals(strings[0], result);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class StringAnyAggregationTest method testStringAnyBufferAggregatorWithNullFirst.
@Test
public void testStringAnyBufferAggregatorWithNullFirst() {
valueSelector = new TestObjectColumnSelector<>(stringsWithNullFirst);
colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
EasyMock.expect(colSelectorFactory.getColumnCapabilities("nilly")).andReturn(new ColumnCapabilitiesImpl().setType(ColumnType.STRING));
EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(valueSelector);
EasyMock.replay(colSelectorFactory);
BufferAggregator agg = stringAnyAggFactory.factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[stringAnyAggFactory.getMaxIntermediateSize()]);
agg.init(buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
aggregate(agg, buffer, 0);
String result = (String) agg.get(buffer, 0);
Assert.assertNull(result);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class DoubleFirstAggregationTest method testDoubleFirstBufferAggregatorWithTimeColumn.
@Test
public void testDoubleFirstBufferAggregatorWithTimeColumn() {
BufferAggregator agg = new DoubleFirstAggregatorFactory("billy", "nilly", "customTime").factorizeBuffered(colSelectorFactory);
ByteBuffer buffer = ByteBuffer.wrap(new byte[doubleFirstAggFactory.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(doubleValues[1], result.rhs, 0.0001);
Assert.assertEquals((long) doubleValues[1], agg.getLong(buffer, 0));
Assert.assertEquals(doubleValues[1], agg.getDouble(buffer, 0), 0.0001);
}
use of org.apache.druid.query.aggregation.BufferAggregator in project druid by druid-io.
the class LongAnyAggregationTest method testLongAnyBufferAggregator.
@Test
public void testLongAnyBufferAggregator() {
BufferAggregator agg = longAnyAggFactory.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(longs[0], result, 0.0001);
Assert.assertEquals((long) longs[0], agg.getLong(buffer, 0));
Assert.assertEquals(longs[0], agg.getLong(buffer, 0), 0.0001);
}
Aggregations