-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Support parsing subqueries with OuterReferenceColumn
belongs to non-adjacent outer relations
#16186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Support parsing subqueries with OuterReferenceColumn
belongs to non-adjacent outer relations
#16186
Changes from all commits
2a828ed
dea0b70
5ed2d24
c2caf37
cec566a
699424d
4edaf61
244a778
f0a5f8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,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>, | ||
|
||
/// The query schema of the outer query plan, used to resolve the columns in subquery | ||
/// This field is maintained to support deprecated functions | ||
/// `outer_query_schema` and `set_outer_query_schema` | ||
/// which is only aware of the adjacent outer relation | ||
outer_query_schema: Option<DFSchemaRef>, | ||
/// The joined schemas of all FROM clauses planned so far. When planning LATERAL | ||
/// FROM clauses, this should become a suffix of the `outer_query_schema`. | ||
|
@@ -220,6 +228,7 @@ impl PlannerContext { | |
prepare_param_data_types: Arc::new(vec![]), | ||
ctes: HashMap::new(), | ||
outer_query_schema: None, | ||
outer_queries_schemas_stack: vec![], | ||
outer_from_schema: None, | ||
create_table_schema: None, | ||
} | ||
|
@@ -234,13 +243,22 @@ impl PlannerContext { | |
self | ||
} | ||
|
||
// Return a reference to the outer query's schema | ||
/// Return a reference to the outer query's schema | ||
/// This function should not be used together with | ||
/// `outer_queries_schemas`, `append_outer_query_schema` | ||
/// `latest_outer_query_schema` and `pop_outer_query_schema` | ||
#[deprecated(note = "Use outer_queries_schemas instead")] | ||
pub fn outer_query_schema(&self) -> Option<&DFSchema> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a breaking change. You can either make a new function or have the PR marked with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh right 👍 |
||
self.outer_query_schema.as_ref().map(|s| s.as_ref()) | ||
} | ||
|
||
/// Sets the outer query schema, returning the existing one, if | ||
/// any | ||
/// any, this function should not be used together with | ||
/// `outer_queries_schemas`, `append_outer_query_schema` | ||
/// `latest_outer_query_schema` and `pop_outer_query_schema` | ||
#[deprecated( | ||
note = "This struct is now aware of a stack of schemas, check pop_outer_query_schema" | ||
)] | ||
pub fn set_outer_query_schema( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, but this can simply be deprecated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, old methods were deprecated |
||
&mut self, | ||
mut schema: Option<DFSchemaRef>, | ||
|
@@ -249,6 +267,28 @@ impl PlannerContext { | |
schema | ||
} | ||
|
||
/// Return the stack of outer relations' schemas, the outer most | ||
/// relation are at the first entry | ||
pub fn outer_queries_schemas(&self) -> Vec<DFSchemaRef> { | ||
self.outer_queries_schemas_stack.to_vec() | ||
} | ||
|
||
/// Sets the outer query schema, returning the existing one, if | ||
/// any | ||
pub fn append_outer_query_schema(&mut self, schema: DFSchemaRef) { | ||
self.outer_queries_schemas_stack.push(schema); | ||
} | ||
|
||
/// The schema of the adjacent outer relation | ||
pub fn latest_outer_query_schema(&mut self) -> Option<DFSchemaRef> { | ||
self.outer_queries_schemas_stack.last().cloned() | ||
} | ||
|
||
/// Remove the schema of the adjacent outer relation | ||
pub fn pop_outer_query_schema(&mut self) -> Option<DFSchemaRef> { | ||
self.outer_queries_schemas_stack.pop() | ||
} | ||
|
||
pub fn set_table_schema( | ||
&mut self, | ||
mut schema: Option<DFSchemaRef>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when we allow nested subquery, the final plan reaches this optimizor and the predicate on scalar_subquery can be accidentally push down