-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: unparser generates wrong sql for derived table with columns #11505
fix: unparser generates wrong sql for derived table with columns #11505
Conversation
* fix unparser for derived table with columns * refactoring * renaming * case in tests
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 @y-f-u -- this seems like an improvement to me.
I left a suggestions for an additional test but I also think we could do that as a follow on
cc @goldmedal
// | ||
// Caveat: this won't handle the case like `select * from (select 1, 2) AS a (b, c)` | ||
// as the parser gives a wrong plan which has mismatch `Int(1)` types: Literal and | ||
// Column in the Projections. Once the parser side is fixed, this logic should work |
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 for the comments
// more tests around subquery/derived table roundtrip | ||
TestStatementWithDialect { | ||
sql: "SELECT string_count FROM ( | ||
SELECT |
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 recommend you add a query that has an additional test that selects more than one column and an expression
something like
select string_count * 100, id FROM ...
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.
Thanks for the suggestion. This query is actually not working as "CAST" will be presented in the inner projection and the projections matching actually breaks.
Maybe another PR to fix this case.
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.
It might also be worth filing an issue to track the defect
Thanks again @y-f-u |
…che#17) (apache#11505) * fix unparser for derived table with columns * refactoring * renaming * case in tests
apache#11505) * fix unparser for derived table with columns * refactoring * renaming * case in tests
Which issue does this PR close?
Unparser creates invalid sqls for LogicPlan that generated from sql with derived table with columns.
Rationale for this change
See "Which issue does this PR close", also check below comment.
Copy/pasted from the code comments.
What changes are included in this PR?
Introduce a method that probe the SubqueryAlias plan to see if it contains a double layer of projections. If so, extract column alias from the outer layer projection into table alias and use the inner layer projection for relation construction.
Are these changes tested?
Yes
Are there any user-facing changes?
No