Mihai Budiu created CALCITE-7913:
------------------------------------
Summary: LATERAL sub-query that references the outer query fails
with "Unable to implement"
Key: CALCITE-7913
URL: https://issues.apache.org/jira/browse/CALCITE-7913
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.42.0
Reporter: Mihai Budiu
If a LATERAL sub-query references a column of the outer query both directly and
inside a nested EXISTS, Calcite cannot implement the plan. This happens with
expand = false only.
h4. Reproduction
{code:sql}
!use scott
!set outputformat mysql
!set expand false
select *
from (values 2) as b (y),
lateral (select * from (values 3) as c (z)
where c.z > b.y
and exists (select 1 from (values 4) as d (w) where d.w > b.y)) as l;
+---+---+
| Y | Z |
+---+---+
| 2 | 3 |
+---+---+
(1 row)
!ok
{code}
PostgreSQL 14 returns this row. Calcite fails:
{noformat}
java.lang.IllegalStateException: Unable to implement
EnumerableCalc(expr#0=[{inputs}], expr#1=[2], expr#2=[3], expr#3=[4],
expr#4=[$cor0],
expr#5=[$t4.Y], expr#6=[>($t3, $t5)], Y=[$t1], Z=[$t2], $condition=[$t6])
EnumerableValues(tuples=[[{ 4 }]])
Suppressed: java.lang.NullPointerException: Cannot invoke
"org.apache.calcite.adapter.enumerable.RexToLixTranslator$InputGetter.field(...)"
because "getter" is null
{noformat}
With assertions enabled, the error is "AssertionError: Correlation variable
$cor0 should be defined".
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)