use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class DoublesSketchToCDFPostAggregatorTest method emptySketch.
@Test
public void emptySketch() {
final TestDoubleColumnSelectorImpl selector = new TestDoubleColumnSelectorImpl(null);
final Aggregator agg = new DoublesSketchBuildAggregator(selector, 8);
final Map<String, Object> fields = new HashMap<>();
fields.put("sketch", agg.get());
final PostAggregator postAgg = new DoublesSketchToCDFPostAggregator("cdf", new FieldAccessPostAggregator("field", "sketch"), new double[] { 4 });
final double[] histogram = (double[]) postAgg.compute(fields);
Assert.assertNotNull(histogram);
Assert.assertEquals(2, histogram.length);
Assert.assertTrue(Double.isNaN(histogram[0]));
Assert.assertTrue(Double.isNaN(histogram[1]));
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class SketchAggregationTest method testUpdateUnionWithNullInList.
@Test
public void testUpdateUnionWithNullInList() {
List<String> value = new ArrayList<>();
value.add("foo");
value.add(null);
value.add("");
value.add("bar");
List[] columnValues = new List[] { value };
final TestObjectColumnSelector selector = new TestObjectColumnSelector(columnValues);
final Aggregator agg = new SketchAggregator(selector, 4096);
agg.aggregate();
Assert.assertFalse(agg.isNull());
Assert.assertNotNull(agg.get());
Assert.assertTrue(agg.get() instanceof SketchHolder);
Assert.assertEquals(2, ((SketchHolder) agg.get()).getEstimate(), 0);
Assert.assertNotNull(((SketchHolder) agg.get()).getSketch());
Assert.assertEquals(2, ((SketchHolder) agg.get()).getSketch().getEstimate(), 0);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class SketchAggregationTest method testUpdateUnionWithDouble.
@Test
public void testUpdateUnionWithDouble() {
Double[] columnValues = new Double[] { 2.0 };
final TestObjectColumnSelector selector = new TestObjectColumnSelector(columnValues);
final Aggregator agg = new SketchAggregator(selector, 4096);
agg.aggregate();
Assert.assertFalse(agg.isNull());
Assert.assertNotNull(agg.get());
Assert.assertTrue(agg.get() instanceof SketchHolder);
Assert.assertEquals(1, ((SketchHolder) agg.get()).getEstimate(), 0);
Assert.assertNotNull(((SketchHolder) agg.get()).getSketch());
Assert.assertEquals(1, ((SketchHolder) agg.get()).getSketch().getEstimate(), 0);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class DoublesSketchToCDFPostAggregatorTest method normalCase.
@Test
public void normalCase() {
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 DoublesSketchToCDFPostAggregator("cdf", new FieldAccessPostAggregator("field", "sketch"), // half of the distribution is below 4
new double[] { 4 });
final double[] cdf = (double[]) postAgg.compute(fields);
Assert.assertNotNull(cdf);
Assert.assertEquals(2, cdf.length);
Assert.assertEquals(0.5, cdf[0], 0);
Assert.assertEquals(1.0, cdf[1], 0);
}
use of org.apache.druid.query.aggregation.Aggregator in project druid by druid-io.
the class DoublesSketchToRankPostAggregatorTest method normalCase.
@Test
public void normalCase() {
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 DoublesSketchToRankPostAggregator("rank", new FieldAccessPostAggregator("field", "sketch"), 4);
final double rank = (double) postAgg.compute(fields);
Assert.assertEquals(0.5, rank, 0);
}
Aggregations