xiedeyantu commented on code in PR #4970:
URL: https://github.com/apache/calcite/pull/4970#discussion_r3361817676
##########
core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java:
##########
@@ -1533,6 +1533,87 @@ private void
checkSemiOrAntiJoinProjectTranspose(JoinRelType type) {
.check();
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7551">[CALCITE-7551]
+ * Project/Filter/Join transpose and merge rules can duplicate
+ * non-deterministic expressions</a>. JoinProjectTransposeRule must
+ * not pull a project containing a non-deterministic expression above
+ * the join, because it inlines the expression into the new join
+ * condition via {@code mergedProgram.expandLocalRef}. */
+ @Test void testJoinProjectTransposeShouldIgnoreNonDeterministic() {
+ final Function<RelBuilder, RelNode> relFn = b -> b
+ .scan("EMP")
+ .project(b.field("EMPNO"),
+ b.alias(b.call(SqlStdOperatorTable.RAND), "r"))
+ .scan("DEPT")
+ .join(JoinRelType.INNER,
+ b.and(
+ b.greaterThan(b.field(2, 0, "r"), b.literal(0.0)),
+ b.lessThan(b.field(2, 0, "r"), b.literal(1.0))))
+ .build();
+
relFn(relFn).withRule(CoreRules.JOIN_PROJECT_LEFT_TRANSPOSE).checkUnchanged();
+ }
+
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7551">[CALCITE-7551]
+ * Project/Filter/Join transpose and merge rules can duplicate
+ * non-deterministic expressions</a>. The transpose is still allowed when
+ * the join condition only references deterministic projected columns,
+ * even if the project also computes a non-deterministic column (here
+ * {@code r} is RAND() but the join is on DEPTNO). */
+ @Test void testJoinProjectTransposeWithUnrelatedNonDeterministic() {
+ final Function<RelBuilder, RelNode> relFn = b -> b
Review Comment:
Would it be possible to convert all the tests to SQL? Using builders
increases the reading complexity and makes the test intent less obvious.
--
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]