alamb commented on code in PR #10954:
URL: https://github.com/apache/datafusion/pull/10954#discussion_r1643447520
##########
datafusion/sql/src/query.rs:
##########
@@ -29,23 +29,17 @@ use sqlparser::ast::{
};
impl<'a, S: ContextProvider> SqlToRel<'a, S> {
- /// Generate a logical plan from an SQL query
+ /// Generate a logical plan from an SQL query/subquery
pub(crate) fn query_to_plan(
&self,
query: Query,
- planner_context: &mut PlannerContext,
+ outer_planner_context: &mut PlannerContext,
) -> Result<LogicalPlan> {
- self.query_to_plan_with_schema(query, planner_context)
- }
+ // Each query has its own planner context, including CTEs that are
visible within that query.
Review Comment:
👍
##########
datafusion/sqllogictest/test_files/cte.slt:
##########
@@ -834,4 +834,28 @@ SELECT * FROM non_recursive_cte, recursive_cte;
query I
WITH t AS (SELECT * FROM t where t.a < 2) SELECT * FROM t
----
-1
\ No newline at end of file
+1
+
+# Issue: https://github.com/apache/datafusion/issues/10914
+# The CTE defined within the subquery is only visible inside that subquery.
+query I rowsort
Review Comment:
I verified that this gets the wrong answer on main:
```
DataFusion CLI v39.0.0
> (WITH t AS (SELECT 400) SELECT * FROM t) UNION (SELECT * FROM t);
+------------+
| Int64(400) |
+------------+
| 400 |
+------------+
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]