From 8e20a1e1f3df6d3588ab1e7768aecbf267481365 Mon Sep 17 00:00:00 2001 From: dclim Date: Wed, 30 Sep 2015 17:11:39 -0600 Subject: [PATCH] Use DoubleSumAggregatorFactory instead of CountAggregatorFactory, add test for non-integers --- .../groupby/GroupByQueryQueryToolChest.java | 7 +++++-- .../query/groupby/GroupByQueryRunnerTest.java | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java index db25f1d759f..fe7a4cd1b98 100644 --- a/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java +++ b/processing/src/main/java/io/druid/query/groupby/GroupByQueryQueryToolChest.java @@ -57,7 +57,7 @@ import io.druid.query.QueryRunner; import io.druid.query.QueryToolChest; import io.druid.query.SubqueryQueryRunner; import io.druid.query.aggregation.AggregatorFactory; -import io.druid.query.aggregation.CountAggregatorFactory; +import io.druid.query.aggregation.DoubleSumAggregatorFactory; import io.druid.query.aggregation.MetricManipulationFn; import io.druid.query.aggregation.PostAggregator; import io.druid.query.dimension.DefaultDimensionSpec; @@ -184,7 +184,10 @@ public class GroupByQueryQueryToolChest extends QueryToolChest aggs = Lists.newArrayList(subquery.getAggregatorSpecs()); for (PostAggregator postAgg : subquery.getPostAggregatorSpecs()) { - aggs.add(new CountAggregatorFactory(postAgg.getName())); // aggregator type doesn't matter here + // This causes the post aggregators from the inner query to be copied to the incremental index so that they are + // available as columns for the outer query. The data isn't modified by the aggregator since it has already + // been fully grouped by the inner query. Somewhat of a hack to get this working with an incremental index. + aggs.add(new DoubleSumAggregatorFactory(postAgg.getName(), postAgg.getName())); } final GroupByQuery innerQuery = new GroupByQuery.Builder(subquery) diff --git a/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java b/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java index febe8e1cd7a..97ad17488b7 100644 --- a/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java +++ b/processing/src/test/java/io/druid/query/groupby/GroupByQueryRunnerTest.java @@ -2460,6 +2460,14 @@ public class GroupByQueryRunnerTest new FieldAccessPostAggregator("idx", "idx"), new FieldAccessPostAggregator("idx", "idx") ) + ), + new ArithmeticPostAggregator( + "post_agg2", + "quotient", + Lists.newArrayList( + new FieldAccessPostAggregator("idx", "idx"), + new ConstantPostAggregator("constant", 1.23) + ) ) ) ) @@ -2474,15 +2482,18 @@ public class GroupByQueryRunnerTest Arrays.asList( new DoubleMaxAggregatorFactory("idx1", "idx"), new DoubleMaxAggregatorFactory("idx2", "idx"), - new DoubleMaxAggregatorFactory("idx3", "post_agg") + new DoubleMaxAggregatorFactory("idx3", "post_agg"), + new DoubleMaxAggregatorFactory("idx4", "post_agg2") ) ) .setGranularity(QueryRunnerTestHelper.dayGran) .build(); List expectedResults = Arrays.asList( - GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "idx1", 2900.0, "idx2", 2900.0, "idx3", 5800.0), - GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "idx1", 2505.0, "idx2", 2505.0, "idx3", 5010.0) + GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "idx1", 2900.0, "idx2", 2900.0, + "idx3", 5800.0, "idx4", 2357.7236328125), + GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "idx1", 2505.0, "idx2", 2505.0, + "idx3", 5010.0, "idx4", 2036.5853271484375) ); Iterable results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);