Skip to content

Commit

Permalink
Support Unnest in Subqueries (#13523)
Browse files Browse the repository at this point in the history
* Add test for subquery unnest

* Add support for Unnest logical plan in inner plan checks
  • Loading branch information
kosiew authored Nov 24, 2024
1 parent 304f51d commit b122bab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion datafusion/optimizer/src/analyzer/subquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ fn check_inner_plan(inner_plan: &LogicalPlan, can_contain_outer_ref: bool) -> Re
| LogicalPlan::Limit(_)
| LogicalPlan::Values(_)
| LogicalPlan::Subquery(_)
| LogicalPlan::SubqueryAlias(_) => {
| LogicalPlan::SubqueryAlias(_)
| LogicalPlan::Unnest(_) => {
inner_plan.apply_children(|plan| {
check_inner_plan(plan, can_contain_outer_ref)?;
Ok(TreeNodeRecursion::Continue)
Expand Down
27 changes: 27 additions & 0 deletions datafusion/sqllogictest/test_files/unnest.slt
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,30 @@ query I
select count(*) from (select unnest(range(0, 100000)) id) t inner join (select unnest(range(0, 100000)) id) t1 on t.id = t1.id;
----
100000


## Unnest in subquery
query IIII
with t as (
select
left1,
width1,
min(column3) as min_height
from
unnest_table a
cross join unnest(ARRAY[1,2,3,4,5,6,7,8,9,10]) as t(left1)
cross join unnest(ARRAY[1,2,3,4,5,6,7,8,9,10]) as t1(width1)
where
left1 + width1 - 1 <= 10
and column3 between left1 and left1 + width1 - 1
group by
left1, width1
)
select
left1, width1, min_height, min_height * width1 as area
from t
where min_height * width1 = (
select max(min_height * width1) from t
)
----
4 7 4 28

0 comments on commit b122bab

Please sign in to comment.