use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class DoublesSketchToHistogramPostAggregatorTest method numBins.
@Test
public void numBins() {
final double[] values = new double[] { 1, 2, 3, 4, 5, 6 };
final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(values);
final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < values.length; i++) {
agg.aggregate();
selector.increment();
}
final Map<String, Object> fields = new HashMap<>();
fields.put("sketch", agg.get());
final PostAggregator postAgg = new DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), null, // two bins of equal mass
2);
final double[] histogram = (double[]) postAgg.compute(fields);
Assert.assertNotNull(histogram);
Assert.assertEquals(2, histogram.length);
Assert.assertEquals(3.0, histogram[0], 0);
Assert.assertEquals(3.0, histogram[1], 0);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class DoublesSketchToQuantilesPostAggregatorTest method normalCase.
@Test
public void normalCase() {
final double[] values = new double[] { 1, 2, 3, 4, 5 };
final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(values);
final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
// noinspection ForLoopReplaceableByForEach
for (int i = 0; i < values.length; i++) {
agg.aggregate();
selector.increment();
}
final Map<String, Object> fields = new HashMap<>();
fields.put("sketch", agg.get());
final PostAggregator postAgg = new DoublesSketchToQuantilesPostAggregator("quantiles", new FieldAccessPostAggregator("field", "sketch"), new double[] { 0, 0.5, 1 });
final double[] quantiles = (double[]) postAgg.compute(fields);
Assert.assertNotNull(quantiles);
Assert.assertEquals(3, quantiles.length);
Assert.assertEquals(1.0, quantiles[0], 0);
Assert.assertEquals(3.0, quantiles[1], 0);
Assert.assertEquals(5.0, quantiles[2], 0);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class LongAnyAggregationTest method testLongAnyAggregator.
@Test
public void testLongAnyAggregator() {
Aggregator agg = longAnyAggFactory.factorize(colSelectorFactory);
aggregate(agg);
aggregate(agg);
aggregate(agg);
aggregate(agg);
Long result = (Long) agg.get();
Assert.assertEquals((Long) longs[0], result);
Assert.assertEquals((long) longs[0], agg.getLong());
Assert.assertEquals(longs[0], agg.getLong(), 0.0001);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class StringAnyAggregationTest method testStringAnyAggregatorWithNullFirst.
@Test
public void testStringAnyAggregatorWithNullFirst() {
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);
Aggregator agg = stringAnyAggFactory.factorize(colSelectorFactory);
aggregate(agg);
aggregate(agg);
aggregate(agg);
aggregate(agg);
String result = (String) agg.get();
Assert.assertNull(result);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class StringAnyAggregationTest method testStringAnyCombiningAggregator.
@Test
public void testStringAnyCombiningAggregator() {
Aggregator agg = combiningAggFactory.factorize(colSelectorFactory);
aggregate(agg);
aggregate(agg);
aggregate(agg);
aggregate(agg);
String result = (String) agg.get();
Assert.assertEquals(strings[0], result);
Assert.assertEquals(strings[0], result);
}
Aggregations