alamb commented on code in PR #18806:
URL: https://github.com/apache/datafusion/pull/18806#discussion_r2691530605
##########
datafusion/sql/src/planner.rs:
##########
@@ -259,7 +259,15 @@ pub struct PlannerContext {
/// Map of CTE name to logical plan of the WITH clause.
/// Use `Arc<LogicalPlan>` to allow cheap cloning
ctes: HashMap<String, Arc<LogicalPlan>>,
+
+ /// The queries schemas of outer query relations, used to resolve the
outer referenced
+ /// columns in subquery (recursive aware)
+ outer_queries_schemas_stack: Vec<DFSchemaRef>,
Review Comment:
I do think this is the key change -- that rather than having a single outer
query schema, we need to have a stack, one for each in the relation.
However it seems like we shouldn't need both `outer_query_schema` as well a
stack of them -- outer_query_schemas should always be enough -- maybe you can
add `push` and `pop` methods that add/remove from the schema stack
One thought I had while looking at this PR is that a more logical structure
would be for each PlannerContext to have a reference to its parent -- something
like
```rust
pub struct PlannerContext<'a> {
/// When planning a subquery, the context of the outer query
parent_context: Option<&'a PlannerContext>
...
}
```
And remove the explicit `outer_query_schema`
--
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]