fix: unparser generates wrong sql for derived table with columns#11505
Merged
alamb merged 1 commit intoapache:mainfrom Jul 19, 2024
Merged
Conversation
* fix unparser for derived table with columns * refactoring * renaming * case in tests
alamb
approved these changes
Jul 18, 2024
Contributor
alamb
left a comment
There was a problem hiding this comment.
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 |
| // more tests around subquery/derived table roundtrip | ||
| TestStatementWithDialect { | ||
| sql: "SELECT string_count FROM ( | ||
| SELECT |
Contributor
There was a problem hiding this comment.
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 ...
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
It might also be worth filing an issue to track the defect
Contributor
|
Thanks again @y-f-u |
Lordworms
pushed a commit
to Lordworms/arrow-datafusion
that referenced
this pull request
Jul 23, 2024
…che#17) (apache#11505) * fix unparser for derived table with columns * refactoring * renaming * case in tests
wiedld
pushed a commit
to influxdata/arrow-datafusion
that referenced
this pull request
Jul 31, 2024
apache#11505) * fix unparser for derived table with columns * refactoring * renaming * case in tests
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?
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