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 @@ -931,7 +931,8 @@ static List<RexNode> rewrite(
(RexCorrelVariable) fieldAccess.getReferenceExpr();
CorDef corDef = new CorDef(v.id, fieldAccess.getField().getIndex());
int newIndex = requireNonNull(unnestedQuery.corDefOutputs.get(corDef));
return new RexInputRef(newIndex, fieldAccess.getType());
return new RexInputRef(
newIndex, unnestedQuery.r.getRowType().getFieldList().get(newIndex).getType());
}
return super.visitFieldAccess(fieldAccess);
}
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/resources/sql/new-decorr.iq
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,28 @@ select deptno from dept d1 where exists (

!ok

# [CALCITE-7402] Two-level nested correlated subquery causes TopDownGeneralDecorrelator type mismatch during translation
# This case comes from sub-query.iq [CALCITE-5716]
!use scott
SELECT dept.deptno, (
SELECT max(emp.empno)
FROM emp
WHERE empno = (SELECT max(empno) AS maxDept
FROM emp e2
WHERE e2.deptno = dept.deptno)
AND emp.deptno = dept.deptno),
dept.dname
FROM dept;
+--------+--------+------------+
| DEPTNO | EXPR$1 | DNAME |
+--------+--------+------------+
| 10 | 7934 | ACCOUNTING |
| 20 | 7902 | RESEARCH |
| 30 | 7900 | SALES |
| 40 | | OPERATIONS |
+--------+--------+------------+
(4 rows)

!ok

# End new-decorr.iq
Loading