use of org.apache.druid.query.aggregation.histogram.QuantilePostAggregator in project druid by druid-io.
the class FixedBucketsHistogramQuantileSqlAggregatorTest method testQuantileOnComplexColumn.
@Test
public void testQuantileOnComplexColumn() throws Exception {
cannotVectorize();
final List<Object[]> expectedResults = ImmutableList.of(new Object[] { 1.0299999713897705, 3.5, 6.293333530426025, 6.470000267028809, 6.494999885559082, 5.497499942779541, 6.499499797821045 });
testQuery("SELECT\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.01, 20, 0.0, 10.0),\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.5, 20, 0.0, 10.0),\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.98, 30, 0.0, 10.0),\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.99, 20, 0.0, 10.0),\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.99, 20, 0.0, 10.0) FILTER(WHERE dim1 = 'abc'),\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.999, 20, 0.0, 10.0) FILTER(WHERE dim1 <> 'abc'),\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.999, 20, 0.0, 10.0) FILTER(WHERE dim1 = 'abc')\n" + "FROM foo", ImmutableList.of(Druids.newTimeseriesQueryBuilder().dataSource(CalciteTests.DATASOURCE1).intervals(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).granularity(Granularities.ALL).aggregators(ImmutableList.of(new FixedBucketsHistogramAggregatorFactory("a0:agg", "fbhist_m1", 20, 0.0, 10.0, FixedBucketsHistogram.OutlierHandlingMode.IGNORE, false), new FixedBucketsHistogramAggregatorFactory("a2:agg", "fbhist_m1", 30, 0.0, 10.0, FixedBucketsHistogram.OutlierHandlingMode.IGNORE, false), new FilteredAggregatorFactory(new FixedBucketsHistogramAggregatorFactory("a4:agg", "fbhist_m1", 20, 0.0, 10.0, FixedBucketsHistogram.OutlierHandlingMode.IGNORE, false), new SelectorDimFilter("dim1", "abc", null)), new FilteredAggregatorFactory(new FixedBucketsHistogramAggregatorFactory("a5:agg", "fbhist_m1", 20, 0.0, 10.0, FixedBucketsHistogram.OutlierHandlingMode.IGNORE, false), new NotDimFilter(new SelectorDimFilter("dim1", "abc", null))))).postAggregators(new QuantilePostAggregator("a0", "a0:agg", 0.01f), new QuantilePostAggregator("a1", "a0:agg", 0.50f), new QuantilePostAggregator("a2", "a2:agg", 0.98f), new QuantilePostAggregator("a3", "a0:agg", 0.99f), new QuantilePostAggregator("a4", "a4:agg", 0.99f), new QuantilePostAggregator("a5", "a5:agg", 0.999f), new QuantilePostAggregator("a6", "a4:agg", 0.999f)).context(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
use of org.apache.druid.query.aggregation.histogram.QuantilePostAggregator in project druid by druid-io.
the class QuantileSqlAggregatorTest method testQuantileOnCastedString.
@Test
public void testQuantileOnCastedString() throws Exception {
cannotVectorize();
final List<Object[]> expectedResults;
if (NullHandling.replaceWithDefault()) {
expectedResults = ImmutableList.of(new Object[] { "", 0.0d }, new Object[] { "a", 0.0d }, new Object[] { "b", 0.0d }, new Object[] { "c", 10.100000381469727d }, new Object[] { "d", 2.0d });
} else {
expectedResults = ImmutableList.of(new Object[] { null, Double.NaN }, new Object[] { "", 1.0d }, new Object[] { "a", Double.NaN }, new Object[] { "b", 10.100000381469727d }, new Object[] { "c", 10.100000381469727d }, new Object[] { "d", 2.0d });
}
testQuery("SELECT dim3, APPROX_QUANTILE(CAST(dim1 as DOUBLE), 0.5) from foo group by dim3", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setVirtualColumns(new ExpressionVirtualColumn("v0", "CAST(\"dim1\", 'DOUBLE')", ColumnType.FLOAT, ExprMacroTable.nil())).setDimensions(new DefaultDimensionSpec("dim3", "d0")).setAggregatorSpecs(new ApproximateHistogramAggregatorFactory("a0:agg", "v0", 50, 7, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false)).setPostAggregatorSpecs(ImmutableList.of(new QuantilePostAggregator("a0", "a0:agg", 0.5f))).setContext(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
use of org.apache.druid.query.aggregation.histogram.QuantilePostAggregator in project druid by druid-io.
the class QuantileSqlAggregatorTest method testQuantileOnInnerQuery.
@Test
public void testQuantileOnInnerQuery() throws Exception {
final List<Object[]> expectedResults;
if (NullHandling.replaceWithDefault()) {
expectedResults = ImmutableList.of(new Object[] { 7.0, 8.26386833190918 });
} else {
expectedResults = ImmutableList.of(new Object[] { 5.25, 6.59091854095459 });
}
testQuery("SELECT AVG(x), APPROX_QUANTILE(x, 0.98)\n" + "FROM (SELECT dim2, SUM(m1) AS x FROM foo GROUP BY dim2)", ImmutableList.of(GroupByQuery.builder().setDataSource(new QueryDataSource(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setDimensions(new DefaultDimensionSpec("dim2", "d0")).setAggregatorSpecs(ImmutableList.of(new DoubleSumAggregatorFactory("a0", "m1"))).setContext(QUERY_CONTEXT_DEFAULT).build())).setInterval(new MultipleIntervalSegmentSpec(ImmutableList.of(Filtration.eternity()))).setGranularity(Granularities.ALL).setAggregatorSpecs(new DoubleSumAggregatorFactory("_a0:sum", "a0"), new CountAggregatorFactory("_a0:count"), new ApproximateHistogramAggregatorFactory("_a1:agg", "a0", null, null, null, null, false)).setPostAggregatorSpecs(ImmutableList.of(new ArithmeticPostAggregator("_a0", "quotient", ImmutableList.of(new FieldAccessPostAggregator(null, "_a0:sum"), new FieldAccessPostAggregator(null, "_a0:count"))), new QuantilePostAggregator("_a1", "_a1:agg", 0.98f))).setContext(QUERY_CONTEXT_DEFAULT).build()), expectedResults);
}
use of org.apache.druid.query.aggregation.histogram.QuantilePostAggregator in project druid by druid-io.
the class FixedBucketsHistogramQuantileSqlAggregatorTest method testGroupByAggregatorDefaultValues.
@Test
public void testGroupByAggregatorDefaultValues() throws Exception {
cannotVectorize();
testQuery("SELECT\n" + "dim2,\n" + "APPROX_QUANTILE_FIXED_BUCKETS(fbhist_m1, 0.01, 20, 0.0, 10.0) FILTER(WHERE dim1 = 'nonexistent'),\n" + "APPROX_QUANTILE_FIXED_BUCKETS(m1, 0.01, 20, 0.0, 10.0) FILTER(WHERE dim1 = 'nonexistent')\n" + "FROM foo WHERE dim2 = 'a' GROUP BY dim2", ImmutableList.of(GroupByQuery.builder().setDataSource(CalciteTests.DATASOURCE1).setInterval(querySegmentSpec(Filtration.eternity())).setDimFilter(selector("dim2", "a", null)).setGranularity(Granularities.ALL).setVirtualColumns(expressionVirtualColumn("v0", "'a'", ColumnType.STRING)).setDimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.STRING)).setAggregatorSpecs(aggregators(new FilteredAggregatorFactory(new FixedBucketsHistogramAggregatorFactory("a0:agg", "fbhist_m1", 20, 0.0, 10.0, FixedBucketsHistogram.OutlierHandlingMode.IGNORE, false), selector("dim1", "nonexistent", null)), new FilteredAggregatorFactory(new FixedBucketsHistogramAggregatorFactory("a1:agg", "m1", 20, 0.0, 10.0, FixedBucketsHistogram.OutlierHandlingMode.IGNORE, false), selector("dim1", "nonexistent", null)))).setPostAggregatorSpecs(ImmutableList.of(new QuantilePostAggregator("a0", "a0:agg", 0.01f), new QuantilePostAggregator("a1", "a1:agg", 0.01f))).setContext(QUERY_CONTEXT_DEFAULT).build()), ImmutableList.of(new Object[] { "a", 0.0, 0.0 }));
}
Aggregations