Skip to content

Commit b122bab

Browse files
authored
Support Unnest in Subqueries (#13523)
* Add test for subquery unnest * Add support for Unnest logical plan in inner plan checks
1 parent 304f51d commit b122bab

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

datafusion/optimizer/src/analyzer/subquery.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ fn check_inner_plan(inner_plan: &LogicalPlan, can_contain_outer_ref: bool) -> Re
163163
| LogicalPlan::Limit(_)
164164
| LogicalPlan::Values(_)
165165
| LogicalPlan::Subquery(_)
166-
| LogicalPlan::SubqueryAlias(_) => {
166+
| LogicalPlan::SubqueryAlias(_)
167+
| LogicalPlan::Unnest(_) => {
167168
inner_plan.apply_children(|plan| {
168169
check_inner_plan(plan, can_contain_outer_ref)?;
169170
Ok(TreeNodeRecursion::Continue)

datafusion/sqllogictest/test_files/unnest.slt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,3 +859,30 @@ query I
859859
select count(*) from (select unnest(range(0, 100000)) id) t inner join (select unnest(range(0, 100000)) id) t1 on t.id = t1.id;
860860
----
861861
100000
862+
863+
864+
## Unnest in subquery
865+
query IIII
866+
with t as (
867+
select
868+
left1,
869+
width1,
870+
min(column3) as min_height
871+
from
872+
unnest_table a
873+
cross join unnest(ARRAY[1,2,3,4,5,6,7,8,9,10]) as t(left1)
874+
cross join unnest(ARRAY[1,2,3,4,5,6,7,8,9,10]) as t1(width1)
875+
where
876+
left1 + width1 - 1 <= 10
877+
and column3 between left1 and left1 + width1 - 1
878+
group by
879+
left1, width1
880+
)
881+
select
882+
left1, width1, min_height, min_height * width1 as area
883+
from t
884+
where min_height * width1 = (
885+
select max(min_height * width1) from t
886+
)
887+
----
888+
4 7 4 28

0 commit comments

Comments
 (0)