-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Support planning subqueries with OuterReferenceColumn belongs to non-adjacent outer relations #19930
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
Open
mkleen
wants to merge
26
commits into
apache:main
Choose a base branch
from
mkleen:plann-recursive-subquery-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+234
−79
Open
feat: Support planning subqueries with OuterReferenceColumn belongs to non-adjacent outer relations #19930
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5dec3b9
fix: allow OuterRefColumn for non-adjacent outer relation
duongcongtoai af21609
fix: accidentally pushdown filter with subquery
duongcongtoai 3247d31
chore: clippy
duongcongtoai 3fbb9ba
chore: rm debug details
duongcongtoai c6d570c
fix: breaking changes
duongcongtoai c4cd3f7
fix: lateral join losing its outer ref columns
duongcongtoai 3d924af
test: more test case for other decorrelation
duongcongtoai df34dc7
doc: better comments
duongcongtoai 68b423f
fix: test
duongcongtoai a83e4d2
Remove outer_query_schema from planner
mkleen 73e9387
Add new tests
mkleen 6144277
fixup! Add new tests
mkleen 193be03
fixup! fixup! Add new tests
mkleen 4dbb62d
Fix fmt
mkleen 0e77c16
Remove test from joins.slt
mkleen 75a6ebb
Remove whitespace in CROSS JOIN output
mkleen ed7b5d9
Return references in planner
mkleen cc9ee37
Add sql logic tests back
mkleen 818926d
Simplify loop logic
mkleen 8a228bc
Fix fmt
mkleen 20583c5
Remove redundant tests for sql integrations
mkleen 510838a
fixup! Remove redundant tests for sql integrations
mkleen 42170bf
fixup! fixup! Remove redundant tests for sql integrations
mkleen 885c337
fixup! fixup! fixup! Remove redundant tests for sql integrations
mkleen d094f13
Fix fmt
mkleen 14aac86
Fix clippy
mkleen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,8 +261,11 @@ 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 query schema of the outer query plan, used to resolve the columns in subquery | ||
| outer_query_schema: Option<DFSchemaRef>, | ||
|
|
||
| /// The queries schemas of outer query relations, used to resolve the outer referenced | ||
|
Contributor
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. perfect |
||
| /// columns in subquery (recursive aware) | ||
| outer_queries_schemas_stack: Vec<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`. | ||
| outer_from_schema: Option<DFSchemaRef>, | ||
|
|
@@ -282,7 +285,7 @@ impl PlannerContext { | |
| Self { | ||
| 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, | ||
| } | ||
|
|
@@ -297,19 +300,26 @@ impl PlannerContext { | |
| self | ||
| } | ||
|
|
||
| // Return a reference to the outer query's schema | ||
| pub fn outer_query_schema(&self) -> Option<&DFSchema> { | ||
| self.outer_query_schema.as_ref().map(|s| s.as_ref()) | ||
| /// Return the stack of outer relations' schemas, the outer most | ||
| /// relation are at the first entry | ||
| pub fn outer_queries_schemas(&self) -> &[DFSchemaRef] { | ||
| &self.outer_queries_schemas_stack | ||
| } | ||
|
|
||
| /// Sets the outer query schema, returning the existing one, if | ||
| /// any | ||
| pub fn set_outer_query_schema( | ||
| &mut self, | ||
| mut schema: Option<DFSchemaRef>, | ||
| ) -> Option<DFSchemaRef> { | ||
| std::mem::swap(&mut self.outer_query_schema, &mut schema); | ||
| schema | ||
| 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() | ||
| } | ||
|
|
||
| /// 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( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,12 +161,26 @@ impl ContextProvider for MockContextProvider { | |
| ])), | ||
| "orders" => Ok(Schema::new(vec![ | ||
| Field::new("order_id", DataType::UInt32, false), | ||
| Field::new("o_orderkey", DataType::UInt32, false), | ||
|
Contributor
Author
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. These extensions were necessary to get the tests to work. |
||
| Field::new("o_custkey", DataType::UInt32, false), | ||
| Field::new("o_orderstatus", DataType::Utf8, false), | ||
| Field::new("customer_id", DataType::UInt32, false), | ||
| Field::new("o_totalprice", DataType::Decimal32(15, 2), false), | ||
| Field::new("o_item_id", DataType::Utf8, false), | ||
| Field::new("qty", DataType::Int32, false), | ||
| Field::new("price", DataType::Float64, false), | ||
| Field::new("delivered", DataType::Boolean, false), | ||
| ])), | ||
| "customer" => Ok(Schema::new(vec![ | ||
| Field::new("c_custkey", DataType::UInt32, false), | ||
| Field::new("c_name", DataType::Utf8, false), | ||
| Field::new("c_address", DataType::Utf8, false), | ||
| Field::new("c_nationkey", DataType::UInt32, false), | ||
| Field::new("c_phone", DataType::Decimal32(15, 2), false), | ||
| Field::new("c_acctbal", DataType::Float64, false), | ||
| Field::new("c_mktsegment", DataType::Utf8, false), | ||
| Field::new("c_comment", DataType::Utf8, false), | ||
| ])), | ||
| "array" => Ok(Schema::new(vec![ | ||
| Field::new( | ||
| "left", | ||
|
|
@@ -186,8 +200,10 @@ impl ContextProvider for MockContextProvider { | |
| ), | ||
| ])), | ||
| "lineitem" => Ok(Schema::new(vec![ | ||
| Field::new("l_orderkey", DataType::UInt32, false), | ||
| Field::new("l_item_id", DataType::UInt32, false), | ||
| Field::new("l_description", DataType::Utf8, false), | ||
| Field::new("l_extendedprice", DataType::Decimal32(15, 2), false), | ||
| Field::new("price", DataType::Float64, false), | ||
| ])), | ||
| "aggregate_test_100" => Ok(Schema::new(vec![ | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: this change is unrelated (it's in my original PR)
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.
This is from fmt.