Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ public static void checkActualAndReferenceFiles() {
sql(sql).withExpand(false).ok();
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-4792">[CALCITE-4792]
* SqlToRel should populate corralateId for join with corralated query in ON condition</a>.
*/
@Test void testJoinOnCorrelatedSubQuery() {
final String sql = "select * from emp inner join dept\n"
+ "on emp.deptno = dept.deptno\n"
+ "and exists (select 1 from emp e2 where e2.deptno = dept.deptno)";
sql(sql).withExpand(false).ok();
}

@Test void testJoinUsing() {
sql("SELECT * FROM emp JOIN dept USING (deptno)").ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4345,6 +4345,24 @@ LogicalValues(tuples=[[{ 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, {
}))], joinType=[left])
LogicalValues(tuples=[[{ 1, 'a' }, { 2, 'b' }]])
LogicalValues(tuples=[[{ 1, 'a' }, { 2, 'b' }]])
]]>
</Resource>
</TestCase>
<TestCase name="testJoinOnCorrelatedSubQuery">
<Resource name="sql">
<![CDATA[select * from emp inner join dept
on emp.deptno = dept.deptno
and exists (select 1 from emp e2 where e2.deptno = dept.deptno)]]>
</Resource>
<Resource name="plan">
<![CDATA[
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], DEPTNO0=[$9], NAME=[$10])
LogicalJoin(condition=[AND(=($7, $9), EXISTS({
LogicalFilter(condition=[=($7, $cor0.DEPTNO0)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}))], joinType=[inner], variablesSet=[[$cor0]])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
</TestCase>
Expand Down
22 changes: 22 additions & 0 deletions core/src/test/resources/sql/sub-query.iq
Original file line number Diff line number Diff line change
Expand Up @@ -10110,5 +10110,27 @@ WHERE E1.SAL > (SELECT B1.COMM FROM BONUS B1 WHERE E1.ENAME = B1.ENAME LIMIT 2);
+--------+
(0 rows)

!ok

# [CALCITE-4792] SqlToRel should populate corralateId for join with corralated query in ON condition.
SELECT emp.ename, dept.dname

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FROM emp INNER JOIN dept
ON emp.deptno = dept.deptno
AND EXISTS (SELECT 1 FROM emp e2 WHERE e2.deptno = dept.deptno AND e2.sal > 2900)
ORDER BY emp.ename;
+--------+------------+
| ENAME | DNAME |
+--------+------------+
| ADAMS | RESEARCH |
| CLARK | ACCOUNTING |
| FORD | RESEARCH |
| JONES | RESEARCH |
| KING | ACCOUNTING |
| MILLER | ACCOUNTING |
| SCOTT | RESEARCH |
| SMITH | RESEARCH |
+--------+------------+
(8 rows)

!ok
# End sub-query.iq
Loading