Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

**Fixes**:

- `sort` step before an `aggregate` step no longer requires its columns in order
to avoid a group by clause error. (@julien-pinchelimouroux, #5347)

**Documentation**:

**Web**:
Expand All @@ -21,6 +24,8 @@

**New Contributors**:

- @julien-pinchelimouroux, with #5347

## 0.13.4 — 2025-03-26

0.13.4 is a small bugfix release.
Expand Down
5 changes: 4 additions & 1 deletion prqlc/prqlc/src/sql/pq/anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,10 @@ pub(super) fn get_requirements(
Super(Filter(expr)) | SqlTransform::Join { filter: expr, .. } => {
CidCollector::collect(expr.clone())
}
Super(Sort(sorts)) => sorts.iter().map(|s| s.column).collect(),
// Aggregations require that all selected columns be wrapped in aggregate functions (e.g., SUM, COUNT).
Super(Sort(sorts)) if !following.contains("Aggregate") => {
sorts.iter().map(|s| s.column).collect()
}
Super(Take(rq::Take { range, .. })) => {
let mut cids = Vec::new();
if let Some(e) = &range.start {
Expand Down
15 changes: 15 additions & 0 deletions prqlc/prqlc/tests/integration/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,21 @@ fn test_sorts_03() {
");
}

#[test]
fn test_sort_before_aggregate() {
assert_snapshot!((compile(r#"
from a
sort a.col
aggregate { result = sum a.col_to_agg }
"#
).unwrap()), @r"
SELECT
COALESCE(SUM(col_to_agg), 0) AS result
FROM
a
");
}

#[test]
fn test_numbers() {
let query = r###"
Expand Down
Loading