Skip to content

Commit 70a6a4b

Browse files
max-sixtyclaude
andcommitted
test: Add coverage for MSSQL DISTINCT+FETCH fix
Expands test_mssql_distinct_fetch() to cover additional code paths: - ExprWithAlias: column with alias uses alias for ORDER BY - Multiple columns: first column is used for ORDER BY Follow-up to PRQL#5630 to improve code coverage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 2ef6835 commit 70a6a4b

File tree

1 file changed

+41
-0
lines changed
  • prqlc/prqlc/tests/integration

1 file changed

+41
-0
lines changed

prqlc/prqlc/tests/integration/sql.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,8 @@ fn test_take_mssql() {
23692369
fn test_mssql_distinct_fetch() {
23702370
// Issue #5628: MSSQL requires ORDER BY items to appear in SELECT list when DISTINCT is used.
23712371
// Using (SELECT NULL) for ORDER BY with DISTINCT is invalid in MSSQL.
2372+
2373+
// Case 1: UnnamedExpr - simple column reference
23722374
assert_snapshot!((compile(r#"
23732375
prql target:sql.mssql
23742376
@@ -2386,6 +2388,45 @@ fn test_mssql_distinct_fetch() {
23862388
FETCH FIRST
23872389
100 ROWS ONLY
23882390
"###);
2391+
2392+
// Case 2: ExprWithAlias - uses the alias for ORDER BY
2393+
assert_snapshot!((compile(r#"
2394+
prql target:sql.mssql
2395+
2396+
from t
2397+
take 100
2398+
group {d = this.`District`} (take 1)
2399+
select {d}
2400+
"#).unwrap()), @r###"
2401+
SELECT
2402+
DISTINCT "District" AS d
2403+
FROM
2404+
t
2405+
ORDER BY
2406+
d OFFSET 0 ROWS
2407+
FETCH FIRST
2408+
100 ROWS ONLY
2409+
"###);
2410+
2411+
// Case 3: Multiple columns - uses first column for ORDER BY
2412+
assert_snapshot!((compile(r#"
2413+
prql target:sql.mssql
2414+
2415+
from t
2416+
take 100
2417+
group {this.`A`, this.`B`} (take 1)
2418+
select {this.`A`, this.`B`}
2419+
"#).unwrap()), @r###"
2420+
SELECT
2421+
DISTINCT "A",
2422+
"B"
2423+
FROM
2424+
t
2425+
ORDER BY
2426+
"A" OFFSET 0 ROWS
2427+
FETCH FIRST
2428+
100 ROWS ONLY
2429+
"###);
23892430
}
23902431

23912432
#[test]

0 commit comments

Comments
 (0)