Skip to content

SQL: Verify GROUP BY ordering on grouped columns #30585

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

Merged
merged 3 commits into from
May 15, 2018

Conversation

costin
Copy link
Member

@costin costin commented May 14, 2018

Due to the way composite aggregation works, ordering in GROUP BY can be
applied only through grouped columns which now the analyzer verifier
enforces.

Fix #29900

Due to the way composite aggregation works, ordering in GROUP BY can be
applied only through grouped columns which now the analyzer verifier
enforces.

Fix 29900
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@costin costin requested review from nik9000 and astefan May 14, 2018 17:33
@costin costin merged commit 09329eb into elastic:master May 15, 2018
costin added a commit that referenced this pull request May 15, 2018
Due to the way composite aggregation works, ordering in GROUP BY can be
applied only through grouped columns which now the analyzer verifier
enforces.

Fix 29900
costin added a commit to costin/elasticsearch that referenced this pull request May 15, 2018
Due to the way composite aggregation works, ordering in GROUP BY can be
applied only through grouped columns which now the analyzer verifier
enforces.

Fix 29900
@costin costin deleted the fix-for-29900 branch May 15, 2018 19:52
@bleskes bleskes added v6.3.0 and removed v6.3.1 labels May 16, 2018
@lukasolson
Copy link
Member

Ran into this today, and tried this as a workaround:

SELECT *
FROM (
  SELECT app.name, SUM(duration) AS total_duration
  FROM qbserve
  WHERE category.productivity = 1
  GROUP BY app.name
)
ORDER BY total_duration DESC

Didn't get an error, but the results also weren't sorted. 🤷‍♂️ Does this mean this is still an issue?

@bpintea
Copy link
Contributor

bpintea commented Aug 3, 2020

Didn't get an error, but the results also weren't sorted. 🤷‍♂️ Does this mean this is still an issue?

For the posterity: no, besides grouped field, ordering by an agg function (like SUM(duration)) will also work and same should the ordering (which seems to be the case... by now?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL: ORDER BY a function doesn't actually order nor complains about not being able to
7 participants