You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/09/20 05:22:52 UTC

[GitHub] [calcite] libenchao commented on a diff in pull request #2911: [CALCITE-5127] Error when executing query with subquery in select lis…

libenchao commented on code in PR #2911:
URL: https://github.com/apache/calcite/pull/2911#discussion_r974896291


##########
core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java:
##########
@@ -481,6 +481,18 @@ public TrimResult trimFields(
     final int fieldCount = rowType.getFieldCount();
     final RelNode input = project.getInput();
 
+    boolean containsSubQuery = false;
+    for (RexNode node : project.getProjects()) {
+      if (RexUtil.containsSubQuery(node)) {
+        containsSubQuery = true;
+        break;
+      }
+    }
+    // Do not trim Project's fields before SubQueryRemoveRule applies.
+    if (containsSubQuery) {
+      return result(project, Mappings.createIdentity(fieldCount));
+    }
+

Review Comment:
   The test added in `sub-query.iq` will fail without this change. It surprised me too that this does not affect any existing plan tests. I guess that's because we don't have enough plan tests for sub query. If there is a test case which is affected by this change, then it was already wrong.
   
   Due to the integrity of this issue I think this is ok to keep it in the same PR, WDYT?



-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org