use of org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl in project druid by druid-io.
the class DoublesSketchToHistogramPostAggregatorTest 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 DoublesSketchToHistogramPostAggregator("histogram", new FieldAccessPostAggregator("field", "sketch"), new double[] { 3.5 }, null);
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.TestDoubleColumnSelectorImpl in project druid by druid-io.
the class DoublesSketchToQuantilesPostAggregatorTest 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 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.assertTrue(Double.isNaN(quantiles[0]));
Assert.assertTrue(Double.isNaN(quantiles[1]));
Assert.assertTrue(Double.isNaN(quantiles[2]));
}
use of org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl 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.TestDoubleColumnSelectorImpl 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.TestDoubleColumnSelectorImpl 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