suibianwanwank commented on code in PR #4614:
URL: https://github.com/apache/calcite/pull/4614#discussion_r2498643868


##########
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java:
##########
@@ -804,17 +804,18 @@ protected RexNode removeCorrelationExpr(
       }
     }
 
+    final Correlate correlate = frameStack.peek() == null ? null : 
frameStack.peek().left;
     if (rel.getGroupType() == Aggregate.Group.SIMPLE
         && rel.getGroupSet().isEmpty()
         && !frame.corDefOutputs.isEmpty()
         && (
           // If there is a COUNT, we must call rewriteScalarAggregate (to 
distinguish 0 vs empty)
           hasCount
           ||
-          // Otherwise call only for non-LEFT Correlate, because for LEFT: 
NULL is effectively
-          // the same as empty (which promotes NULL on the RHS)
+          // Otherwise call except if this is a LEFT Correlate with the 
Aggregate being its RHS,
+          // in that case NULL is effectively the same as empty (which 
promotes NULL on the RHS)
           (!parentPropagatesNullValues
-              && requireNonNull(frameStack.peek()).left.getJoinType() != 
JoinRelType.LEFT))) {

Review Comment:
   Ā LGTM, An additional thought is whether an inner join would also work.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to