Use DoubleSumAggregatorFactory instead of CountAggregatorFactory, add test for non-integers

This commit is contained in:
dclim 2015-09-30 17:11:39 -06:00
parent 70ae5ca922
commit 8e20a1e1f3
2 changed files with 19 additions and 5 deletions

View File

@ -57,7 +57,7 @@ import io.druid.query.QueryRunner;
import io.druid.query.QueryToolChest; import io.druid.query.QueryToolChest;
import io.druid.query.SubqueryQueryRunner; import io.druid.query.SubqueryQueryRunner;
import io.druid.query.aggregation.AggregatorFactory; 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.MetricManipulationFn;
import io.druid.query.aggregation.PostAggregator; import io.druid.query.aggregation.PostAggregator;
import io.druid.query.dimension.DefaultDimensionSpec; import io.druid.query.dimension.DefaultDimensionSpec;
@ -184,7 +184,10 @@ public class GroupByQueryQueryToolChest extends QueryToolChest<Row, GroupByQuery
// We need the inner incremental index to have all the columns required by the outer query // We need the inner incremental index to have all the columns required by the outer query
final List<AggregatorFactory> aggs = Lists.newArrayList(subquery.getAggregatorSpecs()); final List<AggregatorFactory> aggs = Lists.newArrayList(subquery.getAggregatorSpecs());
for (PostAggregator postAgg : subquery.getPostAggregatorSpecs()) { 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) final GroupByQuery innerQuery = new GroupByQuery.Builder(subquery)

View File

@ -2460,6 +2460,14 @@ public class GroupByQueryRunnerTest
new FieldAccessPostAggregator("idx", "idx"), new FieldAccessPostAggregator("idx", "idx"),
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)
)
) )
) )
) )
@ -2474,15 +2482,18 @@ public class GroupByQueryRunnerTest
Arrays.<AggregatorFactory>asList( Arrays.<AggregatorFactory>asList(
new DoubleMaxAggregatorFactory("idx1", "idx"), new DoubleMaxAggregatorFactory("idx1", "idx"),
new DoubleMaxAggregatorFactory("idx2", "idx"), new DoubleMaxAggregatorFactory("idx2", "idx"),
new DoubleMaxAggregatorFactory("idx3", "post_agg") new DoubleMaxAggregatorFactory("idx3", "post_agg"),
new DoubleMaxAggregatorFactory("idx4", "post_agg2")
) )
) )
.setGranularity(QueryRunnerTestHelper.dayGran) .setGranularity(QueryRunnerTestHelper.dayGran)
.build(); .build();
List<Row> expectedResults = Arrays.asList( List<Row> expectedResults = Arrays.asList(
GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "idx1", 2900.0, "idx2", 2900.0, "idx3", 5800.0), GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-01", "idx1", 2900.0, "idx2", 2900.0,
GroupByQueryRunnerTestHelper.createExpectedRow("2011-04-02", "idx1", 2505.0, "idx2", 2505.0, "idx3", 5010.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); Iterable<Row> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);