Skip to content

Commit 394c590

Browse files
max-sixtyclaude
andauthored
fix: Preserve sort with empty group {} (#5635)
Co-authored-by: Claude <[email protected]>
1 parent 1d3538a commit 394c590

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

prqlc/prqlc/src/semantic/resolver/flatten.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ impl PlFold for Flattener {
7777
}
7878
TransformKind::Group { by, pipeline } => {
7979
let sort_undone = self.sort_undone;
80-
self.sort_undone = true;
80+
// Only mark sort as undone if there's an actual partition.
81+
// Empty group {} should preserve sort (fixes #5100).
82+
if !matches!(by.kind, ExprKind::Tuple(ref fields) if fields.is_empty()) {
83+
self.sort_undone = true;
84+
}
8185

8286
let input = self.fold_expr(*t.input)?;
8387

prqlc/prqlc/tests/integration/sql.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6720,3 +6720,24 @@ fn test_group_with_only_sort() {
67206720
employees AS a
67216721
");
67226722
}
6723+
6724+
#[test]
6725+
fn test_group_empty_preserves_sort() {
6726+
// Issue #5100: Empty group {} should preserve inner sort.
6727+
assert_snapshot!(compile(r###"
6728+
from foo
6729+
group {} (
6730+
sort a
6731+
take 1
6732+
)
6733+
"###).unwrap(), @r"
6734+
SELECT
6735+
*
6736+
FROM
6737+
foo
6738+
ORDER BY
6739+
a
6740+
LIMIT
6741+
1
6742+
");
6743+
}

0 commit comments

Comments
 (0)