mirror of https://github.com/apache/druid.git
Use DoubleSumAggregatorFactory instead of CountAggregatorFactory, add test for non-integers
This commit is contained in:
parent
70ae5ca922
commit
8e20a1e1f3
|
@ -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<Row, GroupByQuery
|
|||
// 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)
|
||||
|
|
|
@ -2460,6 +2460,14 @@ public class GroupByQueryRunnerTest
|
|||
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(
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue