You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/05/17 02:14:27 UTC
[3/4] incubator-calcite git commit: [CALCITE-733] Multiple
distinct-COUNT query gives wrong results
[CALCITE-733] Multiple distinct-COUNT query gives wrong results
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/0e7de28f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/0e7de28f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/0e7de28f
Branch: refs/heads/master
Commit: 0e7de28f92caf5d2692603ea18b0776a35149686
Parents: bf86ef9
Author: Julian Hyde <jh...@apache.org>
Authored: Fri May 15 20:01:35 2015 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Fri May 15 21:38:57 2015 -0700
----------------------------------------------------------------------
.../AggregateExpandDistinctAggregatesRule.java | 17 +++++++++++++++--
core/src/test/resources/sql/agg.oq | 16 ++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/0e7de28f/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java
index e05c781..96a031a 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/AggregateExpandDistinctAggregatesRule.java
@@ -328,10 +328,23 @@ public final class AggregateExpandDistinctAggregatesRule extends RelOptRule {
aggCallList.add(newAggCall);
}
+ final Map<Integer, Integer> map = new HashMap<>();
+ for (Integer key : aggregate.getGroupSet()) {
+ map.put(key, map.size());
+ }
+ final ImmutableBitSet newGroupSet = aggregate.getGroupSet().permute(map);
+ assert newGroupSet
+ .equals(ImmutableBitSet.range(aggregate.getGroupSet().cardinality()));
+ ImmutableList<ImmutableBitSet> newGroupingSets = null;
+ if (aggregate.indicator) {
+ newGroupingSets =
+ ImmutableBitSet.ORDERING.immutableSortedCopy(
+ ImmutableBitSet.permute(aggregate.getGroupSets(), map));
+ }
+
Aggregate distinctAgg =
aggregate.copy(aggregate.getTraitSet(), distinct, aggregate.indicator,
- ImmutableBitSet.range(aggregate.getGroupSet().cardinality()),
- aggregate.getGroupSets(), aggCallList);
+ newGroupSet, newGroupingSets, aggCallList);
// If there's no left child yet, no need to create the join
if (left == null) {
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/0e7de28f/core/src/test/resources/sql/agg.oq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/agg.oq b/core/src/test/resources/sql/agg.oq
index c54655e..501b945 100644
--- a/core/src/test/resources/sql/agg.oq
+++ b/core/src/test/resources/sql/agg.oq
@@ -675,4 +675,20 @@ group by deptno;
!ok
+# Multiple distinct count
+select deptno,
+ count(distinct job) as j, count(distinct mgr) as m
+from "scott".emp
+group by deptno;
++--------+---+---+
+| DEPTNO | J | M |
++--------+---+---+
+| 10 | 3 | 2 |
+| 20 | 3 | 4 |
+| 30 | 3 | 2 |
++--------+---+---+
+(3 rows)
+
+!ok
+
# End agg.oq