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


##########
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##########
@@ -1559,6 +1559,56 @@ private void 
checkSemiOrAntiJoinProjectTranspose(JoinRelType type) {
     checkJoinProjectTransposeDoesNotMatch(JoinRelType.LEFT_MARK);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7487";>[CALCITE-7487]
+   * ProjectJoinTransposeRule throws ArrayIndexOutOfBoundsException in
+   * PushProjector when a Join input has a zero-column row type</a>. */
+  @Test void testProjectJoinTransposeWithZeroColumnRightInput() {
+    relFn(b -> zeroColumnJoinInputRelFn(b, false))
+        .withRule(CoreRules.PROJECT_JOIN_TRANSPOSE).check();
+  }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7487";>[CALCITE-7487]
+   * ProjectJoinTransposeRule throws ArrayIndexOutOfBoundsException in
+   * PushProjector when a Join input has a zero-column row type</a>. */
+  @Test void testProjectJoinTransposeWithZeroColumnLeftInput() {
+    relFn(b -> zeroColumnJoinInputRelFn(b, true))
+        .withRule(CoreRules.PROJECT_JOIN_TRANSPOSE).check();
+  }
+
+  /** Builds {@code Project(CAST(col1))} over a cross join in which one input 
is
+   * DEE -- a {@link org.apache.calcite.rel.core.Values} with an empty row 
type,
+   * the identity for cross join. The project must be non-identity, otherwise
+   * {@link RelBuilder} collapses it away and the rule never fires. */
+  private static RelNode zeroColumnJoinInputRelFn(RelBuilder b,

Review Comment:
   Can this be reproduced with a quidem test?
   Not all plans that the builder can build can surface from a real program.



##########
core/src/main/java/org/apache/calcite/rel/rules/PushProjector.java:
##########
@@ -457,13 +457,21 @@ public boolean locateAllRefs() {
         || (childRel instanceof SetOp)) {
       // if nothing is projected from the children, arbitrarily project
       // the first columns; this is necessary since Fennel doesn't
-      // handle 0-column projections
-      if (nProject == 0 && childPreserveExprs.isEmpty()) {
+      // handle 0-column projections.
+      //
+      // An input may legitimately have a zero-column row type -- for
+      // example DEE, the empty-row-type Values that is the identity for

Review Comment:
   What is DEE?



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