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


##########
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java:
##########
@@ -547,9 +552,97 @@ public Result visit(Correlate e) {
     return result(join, leftResult, rightResult);
   }
 
+  /**
+   * Returns whether any expression (including nested sub-queries) references 
a correlated variable
+   * defined by the given input and having the same row type.
+   */
+  private static boolean inputRowTypeMatchesCorrelVariable(
+      RelNode input,
+      Set<CorrelationId> correlIds,
+      Iterable<? extends RexNode> exprs) {
+
+    if (correlIds.isEmpty()) {
+      return false;
+    }
+
+    final RelDataType inputRowType = input.getRowType();
+
+    /** Visitor that detects matching correlated variables. */
+    class Finder extends RexVisitorImpl<Void> {
+      boolean found;
+
+      Finder() {
+        super(true);
+      }
+
+      @Override public Void visitCorrelVariable(RexCorrelVariable v) {
+        if (correlIds.contains(v.id)

Review Comment:
   It looks to me that you are describing a bug, I think having a wrong type on 
the correlated variables should be normally impossible - whoever rewrote the 
filter should have adjusted the variable types too. Am I wrong? If not, can you 
make sure that there is an issue filed for this?
   
   Can a variable have the right type and also be obsolete at the same time?
   
   Also, you can probably add an explanation here as a comment about why the 
type is needed.



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