Skip to content
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

Sorting disappears with empty group #5100

Open
2 tasks done
syko opened this issue Jan 20, 2025 · 2 comments
Open
2 tasks done

Sorting disappears with empty group #5100

syko opened this issue Jan 20, 2025 · 2 comments
Labels
bug Invalid compiler output or panic

Comments

@syko
Copy link

syko commented Jan 20, 2025

What happened?

It seems grouping by nothing is otherwise a valid thing to do, except it makes an inner sort do nothing.

PRQL input

from foo
group {} (
  sort a
  take 1
)

SQL output

SELECT
  *
FROM
  foo
LIMIT
  1

-- Generated by PRQL compiler version:0.13.2 (https://prql-lang.org)

Expected SQL output

SELECT
  *
FROM
  foo
ORDER BY
  a
LIMIT
  1

MVCE confirmation

  • Minimal example
  • New issue

Anything else?

No response

@syko syko added the bug Invalid compiler output or panic label Jan 20, 2025
@kgutwin
Copy link
Collaborator

kgutwin commented Jan 21, 2025

I think this may actually be by design. I recently read through the discussion in #1363 and this comment suggests that using group, even if it is empty, will reset (remove) sorting.

#1363 (comment)

Were you thinking of a use case where you expected sorting to be preserved through an empty group?

@syko
Copy link
Author

syko commented Jan 24, 2025

Ok I see part of it might be by design but if the sorting is private only to the group then I'd say the output should be a combination of CTEs where the sorting still affects the take 1 within the grouping but leaves the final sorting of the relation unaffected.

Our use case is that our prql is dynamically generated so grouping by nothing is just an edge case that we have to handle manually, which is not unreasonable, but from the way aggregations and things are seemingly unaffected by an empty group, we got the impression that group {} is basically noop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Invalid compiler output or panic
Projects
None yet
Development

No branches or pull requests

2 participants