use of org.apache.druid.query.aggregation.TestFloatColumnSelector in project druid by druid-io.
the class FloatAnyAggregationTest method setup.
@Before
public void setup() {
floatAnyAggFactory = new FloatAnyAggregatorFactory("billy", "nilly");
combiningAggFactory = (FloatAnyAggregatorFactory) floatAnyAggFactory.getCombiningFactory();
valueSelector = new TestFloatColumnSelector(floats);
objectSelector = new TestObjectColumnSelector<>(objects);
colSelectorFactory = EasyMock.createMock(ColumnSelectorFactory.class);
EasyMock.expect(colSelectorFactory.makeColumnValueSelector("nilly")).andReturn(valueSelector);
EasyMock.expect(colSelectorFactory.makeColumnValueSelector("billy")).andReturn(objectSelector);
EasyMock.replay(colSelectorFactory);
}
use of org.apache.druid.query.aggregation.TestFloatColumnSelector in project druid by druid-io.
the class ApproximateHistogramPostAggregatorTest method testApproxHistogramCompute.
@Test
public void testApproxHistogramCompute() {
ApproximateHistogram ah = buildHistogram(10, VALUES);
final TestFloatColumnSelector selector = new TestFloatColumnSelector(VALUES);
ApproximateHistogramAggregator agg = new ApproximateHistogramAggregator(selector, 10, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < VALUES.length; i++) {
agg.aggregate();
selector.increment();
}
Map<String, Object> metricValues = new HashMap<String, Object>();
metricValues.put("price", agg.get());
ApproximateHistogramPostAggregator approximateHistogramPostAggregator = new EqualBucketsPostAggregator("approxHist", "price", 5);
Assert.assertEquals(ah.toHistogram(5), approximateHistogramPostAggregator.compute(metricValues));
}
use of org.apache.druid.query.aggregation.TestFloatColumnSelector in project druid by druid-io.
the class ApproximateHistogramAggregatorTest method testBufferAggregate.
@Test
public void testBufferAggregate() {
final float[] values = { 23, 19, 10, 16, 36, 2, 9, 32, 30, 45 };
final int resolution = 5;
final int numBuckets = 5;
final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
ApproximateHistogramAggregatorFactory factory = new ApproximateHistogramAggregatorFactory("billy", "billy", resolution, numBuckets, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false);
ApproximateHistogramBufferAggregator agg = new ApproximateHistogramBufferAggregator(selector, resolution);
ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSizeWithNulls());
int position = 0;
agg.init(buf, position);
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < values.length; i++) {
aggregateBuffer(selector, agg, buf, position);
}
ApproximateHistogram h = ((ApproximateHistogram) agg.get(buf, position));
Assert.assertArrayEquals("final bin positions don't match expected positions", new float[] { 2, 9.5f, 19.33f, 32.67f, 45f }, h.positions, 0.01f);
Assert.assertArrayEquals("final bin counts don't match expected counts", new long[] { 1, 2, 3, 3, 1 }, h.bins());
Assert.assertEquals("getMin value doesn't match expected getMin", 2, h.min(), 0);
Assert.assertEquals("getMax value doesn't match expected getMax", 45, h.max(), 0);
Assert.assertEquals("bin count doesn't match expected bin count", 5, h.binCount());
}
use of org.apache.druid.query.aggregation.TestFloatColumnSelector in project druid by druid-io.
the class FixedBucketsHistogramBufferAggregatorTest method testBufferAggregate.
@Test
public void testBufferAggregate() {
final float[] values = { 23, 19, 10, 16, 36, 2, 9, 32, 30, 45 };
final TestFloatColumnSelector selector = new TestFloatColumnSelector(values);
FixedBucketsHistogramAggregatorFactory factory = new FixedBucketsHistogramAggregatorFactory("billy", "billy", 5, 0, 50, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW, false);
FixedBucketsHistogramBufferAggregator agg = new FixedBucketsHistogramBufferAggregator(selector, 0, 50, 5, FixedBucketsHistogram.OutlierHandlingMode.OVERFLOW);
ByteBuffer buf = ByteBuffer.allocate(factory.getMaxIntermediateSizeWithNulls());
int position = 0;
agg.init(buf, position);
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < values.length; i++) {
aggregateBuffer(selector, agg, buf, position);
}
FixedBucketsHistogram h = ((FixedBucketsHistogram) agg.get(buf, position));
Assert.assertArrayEquals("final bin counts don't match expected counts", new long[] { 2, 3, 1, 3, 1 }, h.getHistogram());
Assert.assertEquals("getMin value doesn't match expected getMin", 2, h.getMin(), 0);
Assert.assertEquals("getMax value doesn't match expected getMax", 45, h.getMax(), 0);
Assert.assertEquals("count doesn't match expected count", 10, h.getCount());
}
Aggregations