mihaibudiu commented on code in PR #4328:
URL: https://github.com/apache/calcite/pull/4328#discussion_r2073975453


##########
core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java:
##########
@@ -561,6 +650,23 @@ public TrimResult trimFields(
     return result(newProject, mapping, project);
   }
 
+  private RexNode changeCorrelateReferences(
+      RexSubQuery node,
+      CorrelationId corrId,
+      RelDataType rowType,
+      Mapping inputMapping) {
+    assert node.getKind() == SqlKind.SCALAR_QUERY : node.getKind();

Review Comment:
   if you want to provide a message for assert you may as well provide a 
message that a human can interpret, like "Expected a SCALAR_QUERY, found " + 
node.getKind().



##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -910,6 +910,24 @@ private static void matchJoin(SubQueryRemoveRule rule, 
RelOptRuleCall call) {
     int nFieldsLeft = join.getLeft().getRowType().getFieldCount();
     int nFieldsRight = join.getRight().getRowType().getFieldCount();
 
+    // Correlation columns should also be considered.
+    // For example:
+    //                                   LogicalJoin
+    //              left                                          right
+    //                |                                             |
+    // LogicalProject.NONE.[0, 1]                            
LogicalValues.NONE.[0]
+    // RecordType(INTEGER DEPTNO, CHAR(11) DNAME)            
RecordType(INTEGER DEPTNO)
+    //
+    // and subquery: $SCALAR_QUERY with correlate
+    // LogicalProject(DEPTNO=[$1])
+    //   LogicalFilter(condition=[=(CAST($0):CHAR(11) NOT NULL, $cor0.DNAME)])
+    //
+    // In such a case $cor0.DNAME need to be accounted as input form left side.

Review Comment:
   you could at least add this as a test



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