Repository navigation
Sort by an expression of the GROUP BY key to close #2817 - #2999
Open
mateuscmtropical wants to merge 2 commits into
Open
mateuscmtropical wants to merge 2 commits into
mateuscmtropical wants to merge 2 commits into
Conversation
Member
|
Thanks, ORDER BY LOWER(c) after GROUP BY LOWER(c) now sorts, and so does ORDER BY a % 2. query.groupColumns also holds SELECT expressions without an alias, and the group row doesn't carry their values. So this PR breaks the following SQL Maybe limit the lookup to the GROUP BY keys, and add these three as tests cases? |
Contributor
Author
|
Done. The lookup now reads from the group row only the expressions that are GROUP BY keys. Anything else is computed from the key columns as before. Your three queries are tests F, G and H in test2817.js, and they failed on the previous commit. |
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.
Closes #2817
What was wrong
In a grouped query, an ORDER BY key that is not a column was compiled with
v.toJS('g', ''). ForORDER BY LOWER(c)that readsg['c'], which the group row does not have. Every key was empty, so the rows kept their insertion order.What changed
compileSelectGroup2collects the GROUP BY expressions that are not bare columns, including the ones inside ROLLUP, CUBE and GROUPING SETS. When an ORDER BY expression is one of them, likeLOWER(c)afterGROUP BY LOWER(c), it reads the value the group row already has. Any other expression, likea*2afterGROUP BY a, is computed from the key columns as before.Tests
test/test2817.jscovers ORDER BY the key expression with an alias, without an alias and DESC, with HAVING, ORDER BY the alias, an operator expression (a % 2), and expressions that are not GROUP BY keys (a*2,a+bandUPPER(c)). The first three fail ondevelop.yarn test-onlygives 2559 pass. The only failures are the 5Test 418cases that load files from the internet.