You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/06/15 19:33:31 UTC

[GitHub] [calcite] devozerov commented on a change in pull request #2437: [CALCITE-4616] AggregateUnionTransposeRule causes row type mismatch when some inputs have unique grouping key (Vladimir Ozerov)

devozerov commented on a change in pull request #2437:
URL: https://github.com/apache/calcite/pull/2437#discussion_r652092993



##########
File path: core/src/main/java/org/apache/calcite/rel/rules/AggregateUnionTransposeRule.java
##########
@@ -125,30 +125,34 @@ public AggregateUnionTransposeRule(Class<? extends Aggregate> aggregateClass,
       return;
     }
 
-    // create corresponding aggregates on top of each union child
-    final RelBuilder relBuilder = call.builder();
-    int transformCount = 0;
+    boolean hasNonUniqueInputs = false;
     final RelMetadataQuery mq = call.getMetadataQuery();
     for (RelNode input : union.getInputs()) {
       boolean alreadyUnique =
           RelMdUtil.areColumnsDefinitelyUnique(mq, input,
               aggRel.getGroupSet());
 
-      relBuilder.push(input);
       if (!alreadyUnique) {
-        ++transformCount;
-        relBuilder.aggregate(relBuilder.groupKey(aggRel.getGroupSet()),
-            aggRel.getAggCallList());
+        hasNonUniqueInputs = true;
+        break;
       }
     }
 
-    if (transformCount == 0) {
+    if (!hasNonUniqueInputs) {

Review comment:
       This variable tracks whether there is at least one input where the group key is not unique. If there are no such inputs (i.e. all inputs already unique on the grouping key), then we return, because the pushdown doesn't make sense. Otherwise - if there is at least one non-unique input - we do the pushdown to all inputs. 
   
   Before the fix, we may do a push-down only to some inputs, which might lead to row type mismatch. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org