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


##########
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java:
##########
@@ -257,6 +258,60 @@ public Result visit(Join e) {
     return result(join, leftResult, rightResult);
   }
 
+  private Result maybeFixRenamedFields(Result rightResult, Join e) {
+    // TableModify is treated in a special way inside visit(TableModify 
modify).
+    // Therefore, we need to skip it here
+    Frame last = stack.peekLast();
+    if (last != null && last.r instanceof TableModify) {
+      return rightResult;
+    }
+    // If there is a filter on the stack an additional "SELECT * ... AS tx" is 
added
+    // as wrapper. This could hide the original aliases used inside.
+    // So we need to reflect the renaming of the fields in the join condition,
+    // which was already done in SqlValidatorUtil.deriveJoinRowType
+    if (stack.stream().noneMatch(it -> it.r instanceof Filter)) {
+      return rightResult;
+    }
+    List<String> rightFieldNames = e.getRight().getRowType().getFieldNames();
+    List<String> fieldNames = e.getRowType().getFieldNames();
+    int offset = e.getLeft().getRowType().getFieldCount();
+    boolean hasFieldNameCollision = false;
+    for (int i = 0; i < rightFieldNames.size(); i++) {
+      if (!rightFieldNames.get(i).equals(fieldNames.get(offset + i))) {

Review Comment:
   why is it sufficient to compare with the field with the same relative index 
rather than compare all n^2 pairs?



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