Fix unparser invalid sql for query with order#11527
Merged
alamb merged 5 commits intoapache:mainfrom Jul 22, 2024
Merged
Conversation
…th limit/sort/distinct; fix wrong unparsed query for original query with sort column that is not in select
alamb
approved these changes
Jul 18, 2024
Contributor
alamb
left a comment
There was a problem hiding this comment.
Thank you @y-f-u and @goldmedal for the review
I think it would be good to implement some of the suggestions in this PR from @goldmedal but I think we could also do it as a follow on PR too.
Contributor
Author
|
Thanks @alamb and @goldmedal . I've addressed all the comments, also fixed one missing case that the projected column is an alias. Now all works well :) |
Contributor
|
Doesn't seem related to the changes in this PR. I'll restart the check and if it passes let's file a ticket about the intermittent failure |
This was referenced Jul 19, 2024
Merged
Contributor
|
Filed #11555 for intermittent test failure |
Contributor
Contributor
Author
|
I will fix the conflict |
Contributor
|
Thanks @y-f-u |
Lordworms
pushed a commit
to Lordworms/arrow-datafusion
that referenced
this pull request
Jul 23, 2024
* wip * fix wrong unparsed query for original query that has derived table with limit/sort/distinct; fix wrong unparsed query for original query with sort column that is not in select * clippy * addressed the comments, also fix one issue when selected column is aliased - see test
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?
This PR addresses two issues:
missing order/limit/distinct on derived table
Before the fix, query like
select a from (select a, b from table order by b desc) tmp order by awill only keep theorder by b descat a wrong nesting level after unparsing.order by columns not on select
Before the fix, query like
select a from table order by bwill be unparsed intoselect table.a from (select table.a, table.b from table) order by table.bwhich is invalid as the derived table misses alias.Rationale for this change
To prevent unparser generating invalid sql for above two common scenarios
What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?
No