-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: unparse for subqueryalias #15068
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
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.
Thank you @chenkovsky
datafusion/sql/src/unparser/plan.rs
Outdated
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)); | ||
} | ||
} |
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.
I think you can write this a bit more concisely by unwrapping the error earlier if you wanted:
Something like
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"); |
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.
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");
Thanks @chenkovsky and @alamb for reviewing 👍 |
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