This is an automated email from the ASF dual-hosted git repository.
mbudiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 0551b89033 [CALCITE-5289] Assertion failure in
MultiJoinOptimizeBushyRule
0551b89033 is described below
commit 0551b8903391c1706422a2c1b8b648a6941f39a2
Author: Mihai Budiu <[email protected]>
AuthorDate: Wed Apr 17 18:04:30 2024 -0700
[CALCITE-5289] Assertion failure in MultiJoinOptimizeBushyRule
Signed-off-by: Mihai Budiu <[email protected]>
---
.../calcite/rel/rules/MultiJoinOptimizeBushyRule.java | 11 +++++++++++
.../test/java/org/apache/calcite/test/RelOptRulesTest.java | 9 +++++++++
.../resources/org/apache/calcite/test/RelOptRulesTest.xml | 13 +++++++++++++
3 files changed, 33 insertions(+)
diff --git
a/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
b/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
index 755df10ab2..e502e8c54c 100644
---
a/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
+++
b/core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java
@@ -107,6 +107,17 @@ public class MultiJoinOptimizeBushyRule
final RelMetadataQuery mq = call.getMetadataQuery();
final LoptMultiJoin multiJoin = new LoptMultiJoin(multiJoinRel);
+ for (int i = 0; i < multiJoin.getNumJoinFactors(); i++) {
+ ImmutableBitSet outerJoinFactors = multiJoin.getOuterJoinFactors(i);
+ if (outerJoinFactors == null) {
+ continue;
+ }
+ if (!outerJoinFactors.isEmpty()) {
+ // Refuse to apply this rule to a multijoin with outer joins,
+ // since this rule cannot handle outer joins.
+ return;
+ }
+ }
final List<Vertex> vertexes = new ArrayList<>();
int x = 0;
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index 7e58a5b775..ab80c1b8fd 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -3383,6 +3383,15 @@ class RelOptRulesTest extends RelOptTestBase {
.check();
}
+ /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-5289">
+ * [CALCITE-5289] Assertion failure in MultiJoinOptimizeBushyRule</a>. */
+ @Test void testBushyJoinRule() {
+ final String sql = "select emp.ename from emp LEFT JOIN emp AS emp1 on
emp.ename = emp1.ename";
+ sql(sql).withPreRule(CoreRules.JOIN_TO_MULTI_JOIN)
+ .withRule(CoreRules.MULTI_JOIN_OPTIMIZE_BUSHY)
+ .checkUnchanged();
+ }
+
@Test void testConvertMultiJoinRule() {
final String sql = "select e1.ename from emp e1, dept d, emp e2\n"
+ "where e1.deptno = d.deptno and d.deptno = e2.deptno";
diff --git
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 855a6d5689..237305a629 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -1374,6 +1374,19 @@ LogicalAggregate(group=[{}], EXPR$0=[SUM($0)],
EXPR$1=[COUNT($0)], EXPR$2=[BIT_O
LogicalAggregate(group=[{0}])
LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testBushyJoinRule">
+ <Resource name="sql">
+ <![CDATA[select emp.ename from emp LEFT JOIN emp AS emp1 on emp.ename =
emp1.ename]]>
+ </Resource>
+ <Resource name="planBefore">
+ <![CDATA[
+LogicalProject(ENAME=[$1])
+ MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[INNER,
LEFT]], outerJoinConditions=[[NULL, =($1, $10)]], projFields=[[ALL, ALL]])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
]]>
</Resource>
</TestCase>