Skip to content

Commit

Permalink
Use DoubleSumAggregatorFactory instead of CountAggregatorFactory, add…
Browse files Browse the repository at this point in the history
… test for non-integers
  • Loading branch information
dclim committed Sep 30, 2015
1 parent 70ae5ca commit 8e20a1e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
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;
Expand Down Expand Up @@ -184,7 +184,10 @@ private Sequence<Row> mergeGroupByResults(
// We need the inner incremental index to have all the columns required by the outer query
final List<AggregatorFactory> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,14 @@ public void testDifferentGroupingSubqueryMultipleAggregatorsOnSameField()
new FieldAccessPostAggregator("idx", "idx"),
new FieldAccessPostAggregator("idx", "idx")
)
),
new ArithmeticPostAggregator(
"post_agg2",
"quotient",
Lists.<PostAggregator>newArrayList(
new FieldAccessPostAggregator("idx", "idx"),
new ConstantPostAggregator("constant", 1.23)
)
)
)
)
Expand All @@ -2474,15 +2482,18 @@ public void testDifferentGroupingSubqueryMultipleAggregatorsOnSameField()
Arrays.<AggregatorFactory>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<Row> 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<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
Expand Down

0 comments on commit 8e20a1e

Please sign in to comment.