use of org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAggregatorFactory in project druid by druid-io.
the class DoublesSketchSqlAggregatorTest method testQuantileOnInnerQuantileQuery.
@Test
public void testQuantileOnInnerQuantileQuery() throws Exception {
ImmutableList.Builder<Object[]> builder = ImmutableList.builder();
builder.add(new Object[] { "", 1.0 });
builder.add(new Object[] { "1", 4.0 });
builder.add(new Object[] { "10.1", 2.0 });
builder.add(new Object[] { "2", 3.0 });
builder.add(new Object[] { "abc", 6.0 });
builder.add(new Object[] { "def", 5.0 });
final List<Object[]> expectedResults = builder.build();
testQuery("SELECT dim1, APPROX_QUANTILE_DS(x, 0.5)\n" + "FROM (SELECT dim1, dim2, APPROX_QUANTILE_DS(m1, 0.5) AS x FROM foo GROUP BY dim1, dim2) GROUP BY dim1", Collections.singletonList(GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim1", "d0"), new DefaultDimensionSpec("dim2", "d1")).setAggregatorSpecs(ImmutableList.of(new DoublesSketchAggregatorFactory("a0:agg", "m1", 128))).setPostAggregatorSpecs(ImmutableList.of(new DoublesSketchToQuantilePostAggregator("a0", makeFieldAccessPostAgg("a0:agg"), 0.5f))).setContext(QUERY_CONTEXT_DEFAULT).build())).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("d0", "_d0", ColumnType.STRING)).setAggregatorSpecs(new DoublesSketchAggregatorFactory("_a0:agg", "a0", 128)).setPostAggregatorSpecs(ImmutableList.of(new DoublesSketchToQuantilePostAggregator("_a0", makeFieldAccessPostAgg("_a0:agg"), 0.5f))).setContext(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
use of org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAggregatorFactory in project druid by druid-io.
the class DoublesSketchSqlAggregatorTest method testFailWithSmallMaxStreamLength.
@Test
public void testFailWithSmallMaxStreamLength() throws Exception {
final Map<String, Object> context = new HashMap<>(QUERY_CONTEXT_DEFAULT);
context.put(DoublesSketchApproxQuantileSqlAggregator.CTX_APPROX_QUANTILE_DS_MAX_STREAM_LENGTH, 1);
testQueryThrows("SELECT\n" + "APPROX_QUANTILE_DS(m1, 0.01),\n" + "APPROX_QUANTILE_DS(cnt, 0.5)\n" + "FROM foo", context, Collections.singletonList(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new DoublesSketchAggregatorFactory("a0:agg", "m1", null, 1L), new DoublesSketchAggregatorFactory("a1:agg", "cnt", null, 1L))).postAggregators(new DoublesSketchToQuantilePostAggregator("a0", makeFieldAccessPostAgg("a0:agg"), 0.01f), new DoublesSketchToQuantilePostAggregator("a1", makeFieldAccessPostAgg("a1:agg"), 0.50f)).context(context).build()), expectedException -> {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("NullPointerException was thrown while updating Doubles sketch");
});
}
Aggregations