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


##########
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:
   I could also add the "counter-example" as a unit test in 
RelDecorrelatorTest, but it would require some minor adjustments in 
RelDecorrelator to allow running the decorrelation algorithm without any type 
of rule prior. It's manageable, adds more flexibility (and can be done in a way 
to keep things backward-compatible)



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