Search in sources :

Example 6 with DoublesSketchAggregatorFactory

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);
}
Also used : QueryDataSource(org.apache.druid.query.QueryDataSource) ImmutableList(com.google.common.collect.ImmutableList) DoublesSketchToQuantilePostAggregator(org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchToQuantilePostAggregator) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) DoublesSketchAggregatorFactory(org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAggregatorFactory) DefaultDimensionSpec(org.apache.druid.query.dimension.DefaultDimensionSpec) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Example 7 with DoublesSketchAggregatorFactory

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");
    });
}
Also used : HashMap(java.util.HashMap) DoublesSketchToQuantilePostAggregator(org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchToQuantilePostAggregator) MultipleIntervalSegmentSpec(org.apache.druid.query.spec.MultipleIntervalSegmentSpec) DoublesSketchAggregatorFactory(org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAggregatorFactory) BaseCalciteQueryTest(org.apache.druid.sql.calcite.BaseCalciteQueryTest) Test(org.junit.Test)

Aggregations

DoublesSketchAggregatorFactory (org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchAggregatorFactory)7 DoublesSketchToQuantilePostAggregator (org.apache.druid.query.aggregation.datasketches.quantiles.DoublesSketchToQuantilePostAggregator)5 MultipleIntervalSegmentSpec (org.apache.druid.query.spec.MultipleIntervalSegmentSpec)4 BaseCalciteQueryTest (org.apache.druid.sql.calcite.BaseCalciteQueryTest)4 Test (org.junit.Test)4 Nullable (javax.annotation.Nullable)2 RexNode (org.apache.calcite.rex.RexNode)2 QueryDataSource (org.apache.druid.query.QueryDataSource)2 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)2 CountAggregatorFactory (org.apache.druid.query.aggregation.CountAggregatorFactory)2 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)2 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)2 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)2 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)2 ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 FilteredAggregatorFactory (org.apache.druid.query.aggregation.FilteredAggregatorFactory)1 ArithmeticPostAggregator (org.apache.druid.query.aggregation.post.ArithmeticPostAggregator)1 NotDimFilter (org.apache.druid.query.filter.NotDimFilter)1 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)1