Skip to content

Commit 1262307

Browse files
committed
Revert "feat: Default to NULLS LAST (PRQL#2617)"
This reverts commit 967adb9.
1 parent 8cd7e28 commit 1262307

File tree

44 files changed

+101
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+101
-170
lines changed

bindings/prql-elixir/test/prql_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule PRQLTest do
2727
"code": null,
2828
"reason": "Unknown name invalid",
2929
"hint": null,
30-
"span": "1:0-7",
30+
"span": "span-chars-0-7",
3131
"display": "Error: \n ╭─[:1:1]\n │\n 1 │ invalid\n │ ───┬─── \n │ ╰───── Unknown name invalid\n───╯\n",
3232
"location": {
3333
"start": [0, 0],
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
3+
import yaml
4+
5+
6+
@pytest.fixture()
7+
def example_queries():
8+
website_path = "../../web/website/content/_index.md"
9+
with open(website_path, "r") as f:
10+
website = f.read()
11+
website_yaml = yaml.safe_load(website.replace("---", ""))
12+
showcase_section = website_yaml["showcase_section"]["examples"]
13+
return showcase_section
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
import re
22

33
import prql_python as prql
4-
import pytest
5-
import yaml
6-
7-
8-
@pytest.fixture()
9-
def example_queries():
10-
website_path = "../../web/website/content/_index.md"
11-
with open(website_path, "r") as f:
12-
website = f.read()
13-
website_yaml = yaml.safe_load(website.replace("---", ""))
14-
showcase_section = website_yaml["showcase_section"]["examples"]
15-
return showcase_section
164

175

186
def normalize(sql: str) -> str:
@@ -30,5 +18,5 @@ def test_all_examples(example_queries):
3018
compiled_normalized = normalize(compiled)
3119
truth_normalized = normalize(query["sql"])
3220
assert (
33-
compiled_normalized == truth_normalized
21+
truth_normalized == compiled_normalized
3422
), f"Failed on Query ID: '{query['id']}'"

prql-compiler/src/sql/dialect.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ pub(super) trait DialectHandler: Any + Debug {
202202
right: Box::new(target),
203203
})
204204
}
205-
206-
fn nulls_first(&self) -> Option<bool> {
207-
Some(false)
208-
}
209205
}
210206

211207
impl dyn DialectHandler {
@@ -283,11 +279,6 @@ impl DialectHandler for MsSqlDialect {
283279
fn set_ops_distinct(&self) -> bool {
284280
false
285281
}
286-
287-
fn nulls_first(&self) -> Option<bool> {
288-
// Unsupported for MSSQL
289-
None
290-
}
291282
}
292283

293284
impl DialectHandler for MySqlDialect {
@@ -311,11 +302,6 @@ impl DialectHandler for MySqlDialect {
311302
sql_ast::BinaryOperator::Custom("REGEXP".to_string()),
312303
)
313304
}
314-
315-
fn nulls_first(&self) -> Option<bool> {
316-
// Unsupported for MySQL
317-
None
318-
}
319305
}
320306

321307
impl DialectHandler for ClickHouseDialect {
@@ -381,11 +367,6 @@ impl DialectHandler for DuckDbDialect {
381367
) -> anyhow::Result<sql_ast::Expr> {
382368
self.translate_regex_with_function(search, target, "REGEXP_MATCHES")
383369
}
384-
385-
fn nulls_first(&self) -> Option<bool> {
386-
// `NULLS LAST` is default for DuckDB
387-
None
388-
}
389370
}
390371

391372
#[cfg(test)]

prql-compiler/src/sql/gen_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ pub(super) fn translate_column_sort(
719719
} else {
720720
Some(false)
721721
},
722-
nulls_first: ctx.dialect.nulls_first(),
722+
nulls_first: None,
723723
})
724724
}
725725

prql-compiler/src/tests/test.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,9 @@ fn test_sorts() {
675675
FROM
676676
invoices
677677
ORDER BY
678-
issued_at NULLS LAST,
679-
amount DESC NULLS LAST,
680-
num_of_articles NULLS LAST
678+
issued_at,
679+
amount DESC,
680+
num_of_articles
681681
"###);
682682

683683
assert_display_snapshot!((compile(r###"
@@ -699,7 +699,7 @@ fn test_sorts() {
699699
FROM
700700
table_1 AS table_0
701701
ORDER BY
702-
_expr_0 NULLS LAST
702+
_expr_0
703703
"###);
704704
}
705705

@@ -865,16 +865,16 @@ fn test_window_functions_02() {
865865
SUM(num_books) OVER (
866866
PARTITION BY order_month
867867
ORDER BY
868-
order_day NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
868+
order_day ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
869869
) AS running_total_num_books,
870870
LAG(num_books, 7) OVER (
871871
ORDER BY
872-
order_day NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
872+
order_day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
873873
) AS num_books_last_week
874874
FROM
875875
table_1 AS table_0
876876
ORDER BY
877-
order_day NULLS LAST
877+
order_day
878878
"###);
879879
}
880880

@@ -933,7 +933,7 @@ fn test_window_functions_05() {
933933
RANK() OVER (
934934
PARTITION BY month
935935
ORDER BY
936-
num_orders NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
936+
num_orders ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
937937
),
938938
LAG(num_orders, 7) OVER () AS num_orders_last_week
939939
FROM
@@ -1024,12 +1024,12 @@ fn test_window_functions_10() {
10241024
*,
10251025
SUM(b) OVER (
10261026
ORDER BY
1027-
day NULLS LAST RANGE BETWEEN 4 PRECEDING AND 4 FOLLOWING
1027+
day RANGE BETWEEN 4 PRECEDING AND 4 FOLLOWING
10281028
) AS next_four_days
10291029
FROM
10301030
foo
10311031
ORDER BY
1032-
day NULLS LAST
1032+
day
10331033
"###);
10341034

10351035
// TODO: add test for preceding
@@ -1258,7 +1258,7 @@ fn test_take() {
12581258
FROM
12591259
table_1 AS table_0
12601260
ORDER BY
1261-
name NULLS LAST
1261+
name
12621262
LIMIT
12631263
5
12641264
"###);
@@ -1423,7 +1423,7 @@ fn test_distinct() {
14231423
ROW_NUMBER() OVER (
14241424
PARTITION BY department
14251425
ORDER BY
1426-
salary NULLS LAST
1426+
salary
14271427
) AS _expr_0
14281428
FROM
14291429
employees
@@ -1446,7 +1446,7 @@ fn test_distinct() {
14461446
ROW_NUMBER() OVER (
14471447
PARTITION BY department
14481448
ORDER BY
1449-
salary NULLS LAST
1449+
salary
14501450
) AS _expr_0
14511451
FROM
14521452
employees
@@ -1483,7 +1483,7 @@ fn test_distinct() {
14831483
WHERE
14841484
_expr_0 <= 1
14851485
ORDER BY
1486-
billing_city NULLS LAST
1486+
billing_city
14871487
"###);
14881488
}
14891489

@@ -1634,7 +1634,7 @@ fn test_sql_of_ast_1() {
16341634
title,
16351635
country
16361636
ORDER BY
1637-
title NULLS LAST
1637+
title
16381638
LIMIT
16391639
20
16401640
"###
@@ -1895,7 +1895,7 @@ take 20
18951895
HAVING
18961896
COUNT(*) > 200
18971897
ORDER BY
1898-
sum_gross_cost NULLS LAST
1898+
sum_gross_cost
18991899
LIMIT
19001900
20
19011901
"###);
@@ -1931,7 +1931,7 @@ fn test_prql_to_sql_table() {
19311931
FROM
19321932
employees
19331933
ORDER BY
1934-
tenure NULLS LAST
1934+
tenure
19351935
LIMIT
19361936
50
19371937
), average_salaries AS (
@@ -1951,7 +1951,7 @@ fn test_prql_to_sql_table() {
19511951
newest_employees
19521952
JOIN average_salaries ON newest_employees.country = average_salaries.country
19531953
ORDER BY
1954-
employees.tenure NULLS LAST
1954+
employees.tenure
19551955
"###
19561956
);
19571957
}
@@ -2009,7 +2009,7 @@ fn test_nonatomic() {
20092009
title,
20102010
country
20112011
ORDER BY
2012-
sum_gross_cost NULLS LAST
2012+
sum_gross_cost
20132013
"###);
20142014

20152015
// A aggregate, then sort and filter
@@ -2037,7 +2037,7 @@ fn test_nonatomic() {
20372037
HAVING
20382038
AVG(salary) > 0
20392039
ORDER BY
2040-
sum_gross_cost NULLS LAST
2040+
sum_gross_cost
20412041
"###);
20422042
}
20432043

@@ -3127,7 +3127,7 @@ fn test_custom_transforms() {
31273127
FROM
31283128
tab
31293129
ORDER BY
3130-
name NULLS LAST
3130+
name
31313131
LIMIT
31323132
3
31333133
"###
@@ -3574,7 +3574,7 @@ fn test_excess_columns() {
35743574
FROM
35753575
table_1 AS table_0
35763576
ORDER BY
3577-
_expr_0 NULLS LAST
3577+
_expr_0
35783578
"###
35793579
);
35803580
}

prql-compiler/tests/integration/snapshots/[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ WITH table_1 AS (
1111
FROM
1212
tracks
1313
ORDER BY
14-
bytes DESC NULLS LAST
14+
bytes DESC
1515
LIMIT
1616
20
1717
)
@@ -21,5 +21,5 @@ SELECT
2121
FROM
2222
table_1 AS table_0
2323
ORDER BY
24-
bytes DESC NULLS LAST
24+
bytes DESC
2525

prql-compiler/tests/integration/snapshots/[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ SELECT
1616
FROM
1717
table_1 AS table_0
1818
ORDER BY
19-
album_id NULLS LAST,
20-
genre_id NULLS LAST
19+
album_id,
20+
genre_id
2121

prql-compiler/tests/integration/snapshots/integration__sql@group_all.prql.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ GROUP BY
2323
table_0.album_id,
2424
table_0.title
2525
ORDER BY
26-
table_0.album_id NULLS LAST
26+
table_0.album_id
2727

prql-compiler/tests/integration/snapshots/integration__sql@group_sort.prql.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ table_2 AS (
2020
FROM
2121
table_3 AS table_0
2222
ORDER BY
23-
_expr_0 NULLS LAST
23+
_expr_0
2424
LIMIT
2525
10
2626
)
@@ -30,5 +30,5 @@ SELECT
3030
FROM
3131
table_2 AS table_1
3232
ORDER BY
33-
_expr_0 NULLS LAST
33+
_expr_0
3434

prql-compiler/tests/integration/snapshots/integration__sql@invoice_totals.prql.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ SELECT
2424
SUM(num_tracks) OVER (
2525
PARTITION BY city
2626
ORDER BY
27-
street NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
27+
street ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
2828
) AS running_total_num_tracks,
2929
LAG(num_tracks, 7) OVER (
3030
ORDER BY
31-
city NULLS LAST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
31+
city ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
3232
) AS num_tracks_last_week
3333
FROM
3434
table_1 AS table_0
3535
ORDER BY
36-
city NULLS LAST
36+
city
3737
LIMIT
3838
20
3939

prql-compiler/tests/integration/snapshots/[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ WITH table_1 AS (
1414
REGEXP(name, 'Love')
1515
AND milliseconds / 1000 / 60 BETWEEN 3 AND 4
1616
ORDER BY
17-
track_id NULLS LAST
17+
track_id
1818
LIMIT
1919
15
2020
)
@@ -24,5 +24,5 @@ SELECT
2424
FROM
2525
table_1 AS table_0
2626
ORDER BY
27-
track_id NULLS LAST
27+
track_id
2828

prql-compiler/tests/integration/snapshots/[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ FROM
2121
table_1 AS table_0
2222
LEFT JOIN employees AS manager ON table_0.reports_to = manager.employee_id
2323
ORDER BY
24-
table_0.first_name NULLS LAST,
25-
table_0.last_name NULLS LAST
24+
table_0.first_name,
25+
table_0.last_name
2626

prql-compiler/tests/integration/snapshots/[email protected]

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ WITH table_1 AS (
1414
FROM
1515
tracks
1616
ORDER BY
17-
milliseconds NULLS LAST
17+
milliseconds
1818
LIMIT
1919
10
2020
)
@@ -23,5 +23,5 @@ SELECT
2323
FROM
2424
table_1 AS table_0
2525
ORDER BY
26-
milliseconds NULLS LAST
26+
milliseconds
2727

0 commit comments

Comments
 (0)