fix: unparse for subqueryalias#15068
Merged
goldmedal merged 3 commits intoapache:mainfrom Mar 11, 2025
Merged
Conversation
alamb
approved these changes
Mar 9, 2025
Comment on lines
987
to
997
| let ret = Self::unparse_table_scan_pushdown( | ||
| &subquery_alias.input, | ||
| Some(subquery_alias.alias.clone()), | ||
| already_projected, | ||
| ) | ||
| ); | ||
| if let Some(alias) = alias { | ||
| if let Ok(Some(plan)) = ret { | ||
| let plan = LogicalPlanBuilder::new(plan).alias(alias)?.build()?; | ||
| return Ok(Some(plan)); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
I think you can write this a bit more concisely by unwrapping the error earlier if you wanted:
Something like
Suggested change
| let ret = Self::unparse_table_scan_pushdown( | |
| &subquery_alias.input, | |
| Some(subquery_alias.alias.clone()), | |
| already_projected, | |
| ) | |
| ); | |
| if let Some(alias) = alias { | |
| if let Ok(Some(plan)) = ret { | |
| let plan = LogicalPlanBuilder::new(plan).alias(alias)?.build()?; | |
| return Ok(Some(plan)); | |
| } | |
| } | |
| )?; | |
| if let Some(alias) = alias { | |
| let plan = LogicalPlanBuilder::new(plan).alias(alias)?.build()?; | |
| return Ok(Some(plan)); | |
| } | |
| Ok(ret) |
datafusion/core/tests/sql/select.rs
Outdated
| ctx.register_batch("customer", customer())?; | ||
| let plan = ctx.sql(sql).await?.into_optimized_plan()?; | ||
| let sql = plan_to_sql(&plan)?; | ||
| assert_eq!(sql.to_string(), "SELECT customer_view.c_custkey, customer_view.c_name, customer_view.custkey_plus FROM (SELECT customer.c_custkey, (CAST(customer.c_custkey AS BIGINT) + 1) AS custkey_plus, customer.c_name FROM (SELECT customer.c_custkey, customer.c_name FROM customer AS customer) AS customer) AS customer_view"); |
Contributor
There was a problem hiding this comment.
I parsed this with some structure and it looks right to me
Thanks @chenkovsky
"SELECT
customer_view.c_custkey,
customer_view.c_name,
customer_view.custkey_plus
FROM
(SELECT
customer.c_custkey,
(CAST(customer.c_custkey AS BIGINT) + 1) AS custkey_plus,
customer.c_name
FROM
(SELECT
customer.c_custkey,
customer.c_name
FROM customer AS customer
) AS customer
) AS customer_view");
goldmedal
reviewed
Mar 10, 2025
goldmedal
approved these changes
Mar 11, 2025
Contributor
|
Thanks @chenkovsky and @alamb for reviewing 👍 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
Rationale for this change
the qualifier is incorrect for subqueryalias when unparsing.
What changes are included in this PR?
wrap with subqueryalias if alias is passed when unparsing.
Are these changes tested?
Unittest
Are there any user-facing changes?
No