Skip to content
Open
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
3 changes: 3 additions & 0 deletions datafusion/expr/src/logical_plan/invariants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ fn strip_inner_query(inner_plan: &LogicalPlan) -> &LogicalPlan {
strip_inner_query(projection.input.as_ref())
}
LogicalPlan::SubqueryAlias(alias) => strip_inner_query(alias.input.as_ref()),
LogicalPlan::MaterializedCte(MaterializedCtePlan::Cte(cte)) => {
strip_inner_query(cte.continuation.as_ref())
Comment on lines +419 to +420
}
other => other,
}
}
Expand Down
21 changes: 21 additions & 0 deletions datafusion/sqllogictest/test_files/cte_materialized.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,27 @@ SELECT count(*) FROM pruned
statement ok
DROP TABLE pruned;

# A materialized CTE inside a correlated scalar subquery. The subquery
# aggregates in the continuation of the `MaterializedCte` node.
query II rowsort
SELECT k, (WITH c AS MATERIALIZED (SELECT k AS x, v AS y FROM t)
SELECT max(y) FROM c WHERE c.x = t.k) FROM t
----
1 10
2 20
3 30
4 40

# Outer rows without a match get NULL.
query II rowsort
SELECT k, (WITH c AS MATERIALIZED (SELECT k AS x, v AS y FROM t)
SELECT max(y) FROM c WHERE c.x = t.k + 2) FROM t
----
1 30
2 40
3 NULL
4 NULL

statement ok
DROP TABLE wide;

Expand Down