use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class DoublesSketchToCDFPostAggregatorTest method testResultArraySignature.
@Test
public void testResultArraySignature() {
final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new DoublesSketchAggregatorFactory("sketch", "col", 8)).postAggregators(new DoublesSketchToCDFPostAggregator("a", new FieldAccessPostAggregator("field", "sketch"), new double[] { 4 })).build();
Assert.assertEquals(RowSignature.builder().addTimeColumn().add("sketch", null).add("a", ColumnType.DOUBLE_ARRAY).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator 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.post.FieldAccessPostAggregator in project druid by druid-io.
the class DoublesSketchToCDFPostAggregatorTest method testSerde.
@Test
public void testSerde() throws JsonProcessingException {
final PostAggregator there = new DoublesSketchToCDFPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), new double[] { 0.25, 0.75 });
DefaultObjectMapper mapper = new DefaultObjectMapper();
DoublesSketchToCDFPostAggregator andBackAgain = mapper.readValue(mapper.writeValueAsString(there), DoublesSketchToCDFPostAggregator.class);
Assert.assertEquals(there, andBackAgain);
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class DoublesSketchToCDFPostAggregatorTest method testToString.
@Test
public void testToString() {
final PostAggregator postAgg = new DoublesSketchToCDFPostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), new double[] { 0.25, 0.75 });
Assert.assertEquals("DoublesSketchToCDFPostAggregator{name='post', field=FieldAccessPostAggregator{name='field1', fieldName='sketch'}, splitPoints=[0.25, 0.75]}", postAgg.toString());
}
use of org.apache.druid.query.aggregation.post.FieldAccessPostAggregator in project druid by druid-io.
the class DoublesSketchToQuantilePostAggregatorTest method testToString.
@Test
public void testToString() {
final PostAggregator postAgg = new DoublesSketchToQuantilePostAggregator("post", new FieldAccessPostAggregator("field1", "sketch"), 0.5);
Assert.assertEquals("DoublesSketchToQuantilePostAggregator{name='post', field=FieldAccessPostAggregator{name='field1', fieldName='sketch'}, fraction=0.5}", postAgg.toString());
}
Aggregations