Skip to content

Commit 0551b89

Browse files
committed
[CALCITE-5289] Assertion failure in MultiJoinOptimizeBushyRule
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent b4bcd3b commit 0551b89

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

core/src/main/java/org/apache/calcite/rel/rules/MultiJoinOptimizeBushyRule.java

+11
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ public MultiJoinOptimizeBushyRule(RelFactories.JoinFactory joinFactory,
107107
final RelMetadataQuery mq = call.getMetadataQuery();
108108

109109
final LoptMultiJoin multiJoin = new LoptMultiJoin(multiJoinRel);
110+
for (int i = 0; i < multiJoin.getNumJoinFactors(); i++) {
111+
ImmutableBitSet outerJoinFactors = multiJoin.getOuterJoinFactors(i);
112+
if (outerJoinFactors == null) {
113+
continue;
114+
}
115+
if (!outerJoinFactors.isEmpty()) {
116+
// Refuse to apply this rule to a multijoin with outer joins,
117+
// since this rule cannot handle outer joins.
118+
return;
119+
}
120+
}
110121

111122
final List<Vertex> vertexes = new ArrayList<>();
112123
int x = 0;

core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,15 @@ private void checkPushJoinThroughUnionOnRightDoesNotMatchSemiOrAntiJoin(JoinRelT
33833383
.check();
33843384
}
33853385

3386+
/** Test case for <a href="https://issues.apache.org/jira/browse/CALCITE-5289">
3387+
* [CALCITE-5289] Assertion failure in MultiJoinOptimizeBushyRule</a>. */
3388+
@Test void testBushyJoinRule() {
3389+
final String sql = "select emp.ename from emp LEFT JOIN emp AS emp1 on emp.ename = emp1.ename";
3390+
sql(sql).withPreRule(CoreRules.JOIN_TO_MULTI_JOIN)
3391+
.withRule(CoreRules.MULTI_JOIN_OPTIMIZE_BUSHY)
3392+
.checkUnchanged();
3393+
}
3394+
33863395
@Test void testConvertMultiJoinRule() {
33873396
final String sql = "select e1.ename from emp e1, dept d, emp e2\n"
33883397
+ "where e1.deptno = d.deptno and d.deptno = e2.deptno";

core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml

+13
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,19 @@ LogicalAggregate(group=[{}], EXPR$0=[SUM($0)], EXPR$1=[COUNT($0)], EXPR$2=[BIT_O
13741374
LogicalAggregate(group=[{0}])
13751375
LogicalProject(DEPTNO=[$7])
13761376
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
1377+
]]>
1378+
</Resource>
1379+
</TestCase>
1380+
<TestCase name="testBushyJoinRule">
1381+
<Resource name="sql">
1382+
<![CDATA[select emp.ename from emp LEFT JOIN emp AS emp1 on emp.ename = emp1.ename]]>
1383+
</Resource>
1384+
<Resource name="planBefore">
1385+
<![CDATA[
1386+
LogicalProject(ENAME=[$1])
1387+
MultiJoin(joinFilter=[true], isFullOuterJoin=[false], joinTypes=[[INNER, LEFT]], outerJoinConditions=[[NULL, =($1, $10)]], projFields=[[ALL, ALL]])
1388+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
1389+
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
13771390
]]>
13781391
</Resource>
13791392
</TestCase>

0 commit comments

Comments
 (0)