Skip to content

fix(prqlc, sort): do not require sort columns if it's followed by an aggregation #5347

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

Conversation

julien-pinchelimouroux
Copy link
Contributor

Fixes: #3200

sort always required sorted columns which caused an unwanted column selection in the next aggregate : column <SORTED_COLUMN> must appear in the GROUP BY clause or be used in an aggregate function


To fix it, it simply checks if an aggregate is present in the following transforms


I didn't find a PRQL query where this change can be a regression. If you have something in mind, please share it! 🙏

@max-sixty
Copy link
Member

thanks @julien-pinchelimouroux !

would you mind adding a small test?

I didn't find a PRQL query where this change can be a regression. If you have something in mind, please share it! 🙏

could we use, from #3200

prql target:sql.duckdb
from tb1
sort {c0}
aggregate {new_col = min c1}

I also see lots of snapshot files in the diff — where are those from? (sorry if I'm missing something...)

@julien-pinchelimouroux
Copy link
Contributor Author

Hello @max-sixty !

snap files comes from the following added tests :

  • prqlc/prqlc/tests/integration/queries/sort_with_aggregation.prql
  • prqlc/prqlc/tests/integration/queries/sort_with_aggregation_and_limit.prql

They are based on the reported query in the original issue #3200

@vanillajonathan
Copy link
Collaborator

Maybe a note should be added to the CHANGELOG file?

@max-sixty
Copy link
Member

ah thanks @julien-pinchelimouroux !

could we slim down the test a bit, unless we really need two full integration tests? I'd have thought this could just be a single inline test in prqlc/prqlc/tests/integration/sql.rs ?

@julien-pinchelimouroux
Copy link
Contributor Author

Hi @max-sixty
Yes you're totally right, that do not need a full integration test :)

@max-sixty max-sixty merged commit e3cfae8 into PRQL:main Jul 7, 2025
37 checks passed
@max-sixty
Copy link
Member

great! thank you @julien-pinchelimouroux

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

Successfully merging this pull request may close these issues.

columns not in aggregate function and group by
3 participants