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


##########
core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java:
##########
@@ -610,6 +620,42 @@ public TrimResult trimFields(
     return result(newProject, mapping, project);
   }
 
+  /** Trims the fields of the relational expression wrapped by a sub-query.
+   *
+   * <p>Currently, only scalar sub-queries are trimmed: a scalar sub-query
+   * returns exactly one field, and that field is used by its consumer, so
+   * we can trim the sub-query's internal tree asking for its single output
+   * field. Sub-queries of other kinds (IN, EXISTS, ARRAY, MULTISET, MAP) are
+   * returned unchanged; their output fields are either all significant for
+   * the semantics or not distinguishable, so it is not safe to trim them.
+   *
+   * @param subQuery Sub-query
+   * @return Sub-query whose internal relational expression is trimmed,
+   * or the original sub-query if it cannot be trimmed
+   */
+  protected RexSubQuery trimSubQuery(RexSubQuery subQuery) {
+    if (subQuery.getKind() != SqlKind.SCALAR_QUERY) {
+      return subQuery;
+    }
+    final RelNode rel = subQuery.rel;
+    final int fieldCount = rel.getRowType().getFieldCount();
+    if (fieldCount == 0) {

Review Comment:
   why not compare with 1?



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