Skip to content

Commit 7018a4e

Browse files
committed
test: update ordering spec on asc/desc and nulls_last
1 parent 8a2c57d commit 7018a4e

File tree

8 files changed

+24
-26
lines changed

8 files changed

+24
-26
lines changed

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_dense_rank/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
DENSE_RANK() OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_1`
8+
DENSE_RANK() OVER (ORDER BY `bfcol_0` DESC) AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff/diff_bool.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
`bfcol_0` <> LAG(`bfcol_0`, 1) OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_1`
8+
`bfcol_0` <> LAG(`bfcol_0`, 1) OVER (ORDER BY `bfcol_0` DESC) AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first/out.sql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ WITH `bfcte_0` AS (
88
CASE
99
WHEN `bfcol_0` IS NULL
1010
THEN NULL
11-
ELSE FIRST_VALUE(`bfcol_0`) OVER (
12-
ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST
13-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
14-
)
11+
ELSE FIRST_VALUE(`bfcol_0`) OVER (ORDER BY `bfcol_0` DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
1512
END AS `bfcol_1`
1613
FROM `bfcte_0`
1714
)

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last/out.sql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ WITH `bfcte_0` AS (
88
CASE
99
WHEN `bfcol_0` IS NULL
1010
THEN NULL
11-
ELSE LAST_VALUE(`bfcol_0`) OVER (
12-
ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST
13-
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
14-
)
11+
ELSE LAST_VALUE(`bfcol_0`) OVER (ORDER BY `bfcol_0` DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
1512
END AS `bfcol_1`
1613
FROM `bfcte_0`
1714
)

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_rank/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
RANK() OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_1`
8+
RANK() OVER (ORDER BY `bfcol_0` IS NULL DESC NULLS FIRST, `bfcol_0` DESC NULLS FIRST) AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lag.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
LAG(`bfcol_0`, 1) OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_1`
8+
LAG(`bfcol_0`, 1) OVER (ORDER BY `bfcol_0` ASC) AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lead.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WITH `bfcte_0` AS (
55
), `bfcte_1` AS (
66
SELECT
77
*,
8-
LEAD(`bfcol_0`, 1) OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_1`
8+
LEAD(`bfcol_0`, 1) OVER (ORDER BY `bfcol_0` ASC) AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

tests/unit/core/compile/sqlglot/aggregations/test_unary_compiler.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_all(scalar_types_df: bpd.DataFrame, snapshot):
8080
bf_df_str = scalar_types_df[[col_name, "string_col"]]
8181
window_partition = window_spec.WindowSpec(
8282
grouping_keys=(expression.deref("string_col"),),
83-
ordering=(ordering.ascending_over(col_name),),
83+
ordering=(ordering.descending_over(col_name),),
8484
)
8585
sql_window_partition = _apply_unary_window_op(
8686
bf_df_str, agg_expr, window_partition, "agg_bool"
@@ -121,7 +121,7 @@ def test_any_value(scalar_types_df: bpd.DataFrame, snapshot):
121121
snapshot.assert_match(sql, "out.sql")
122122

123123
# Window tests
124-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
124+
window = window_spec.WindowSpec(ordering=(ordering.descending_over(col_name),))
125125
sql_window = _apply_unary_window_op(bf_df, agg_expr, window, "agg_int64")
126126
snapshot.assert_match(sql_window, "window_out.sql")
127127

@@ -152,7 +152,7 @@ def test_count(scalar_types_df: bpd.DataFrame, snapshot):
152152
bf_df_str = scalar_types_df[[col_name, "string_col"]]
153153
window_partition = window_spec.WindowSpec(
154154
grouping_keys=(expression.deref("string_col"),),
155-
ordering=(ordering.ascending_over(col_name),),
155+
ordering=(ordering.descending_over(col_name),),
156156
)
157157
sql_window_partition = _apply_unary_window_op(
158158
bf_df_str, agg_expr, window_partition, "agg_int64"
@@ -166,7 +166,7 @@ def test_dense_rank(scalar_types_df: bpd.DataFrame, snapshot):
166166
agg_expr = agg_exprs.UnaryAggregation(
167167
agg_ops.DenseRankOp(), expression.deref(col_name)
168168
)
169-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
169+
window = window_spec.WindowSpec(ordering=(ordering.descending_over(col_name),))
170170
sql = _apply_unary_window_op(bf_df, agg_expr, window, "agg_int64")
171171

172172
snapshot.assert_match(sql, "out.sql")
@@ -197,7 +197,7 @@ def test_diff(scalar_types_df: bpd.DataFrame, snapshot):
197197
# Test boolean
198198
bool_col = "bool_col"
199199
bf_df_bool = scalar_types_df[[bool_col]]
200-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(bool_col),))
200+
window = window_spec.WindowSpec(ordering=(ordering.descending_over(bool_col),))
201201
bool_op = agg_exprs.UnaryAggregation(
202202
agg_ops.DiffOp(periods=1), expression.deref(bool_col)
203203
)
@@ -213,7 +213,7 @@ def test_first(scalar_types_df: bpd.DataFrame, snapshot):
213213
col_name = "int64_col"
214214
bf_df = scalar_types_df[[col_name]]
215215
agg_expr = agg_exprs.UnaryAggregation(agg_ops.FirstOp(), expression.deref(col_name))
216-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
216+
window = window_spec.WindowSpec(ordering=(ordering.descending_over(col_name),))
217217
sql = _apply_unary_window_op(bf_df, agg_expr, window, "agg_int64")
218218

219219
snapshot.assert_match(sql, "out.sql")
@@ -243,7 +243,7 @@ def test_last(scalar_types_df: bpd.DataFrame, snapshot):
243243
col_name = "int64_col"
244244
bf_df = scalar_types_df[[col_name]]
245245
agg_expr = agg_exprs.UnaryAggregation(agg_ops.LastOp(), expression.deref(col_name))
246-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
246+
window = window_spec.WindowSpec(ordering=(ordering.descending_over(col_name),))
247247
sql = _apply_unary_window_op(bf_df, agg_expr, window, "agg_int64")
248248

249249
snapshot.assert_match(sql, "out.sql")
@@ -281,7 +281,7 @@ def test_max(scalar_types_df: bpd.DataFrame, snapshot):
281281
bf_df_str = scalar_types_df[[col_name, "string_col"]]
282282
window_partition = window_spec.WindowSpec(
283283
grouping_keys=(expression.deref("string_col"),),
284-
ordering=(ordering.ascending_over(col_name),),
284+
ordering=(ordering.descending_over(col_name),),
285285
)
286286
sql_window_partition = _apply_unary_window_op(
287287
bf_df_str, agg_expr, window_partition, "agg_int64"
@@ -319,7 +319,7 @@ def test_mean(scalar_types_df: bpd.DataFrame, snapshot):
319319
col_name = "int64_col"
320320
bf_df_int = scalar_types_df[[col_name]]
321321
agg_expr = agg_ops.MeanOp().as_expr(col_name)
322-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
322+
window = window_spec.WindowSpec(ordering=(ordering.descending_over(col_name),))
323323
sql_window = _apply_unary_window_op(bf_df_int, agg_expr, window, "agg_int64")
324324
snapshot.assert_match(sql_window, "window_out.sql")
325325

@@ -362,7 +362,7 @@ def test_min(scalar_types_df: bpd.DataFrame, snapshot):
362362
bf_df_str = scalar_types_df[[col_name, "string_col"]]
363363
window_partition = window_spec.WindowSpec(
364364
grouping_keys=(expression.deref("string_col"),),
365-
ordering=(ordering.ascending_over(col_name),),
365+
ordering=(ordering.descending_over(col_name),),
366366
)
367367
sql_window_partition = _apply_unary_window_op(
368368
bf_df_str, agg_expr, window_partition, "agg_int64"
@@ -391,7 +391,9 @@ def test_rank(scalar_types_df: bpd.DataFrame, snapshot):
391391
bf_df = scalar_types_df[[col_name]]
392392
agg_expr = agg_exprs.UnaryAggregation(agg_ops.RankOp(), expression.deref(col_name))
393393

394-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
394+
window = window_spec.WindowSpec(
395+
ordering=(ordering.descending_over(col_name, nulls_last=False),)
396+
)
395397
sql = _apply_unary_window_op(bf_df, agg_expr, window, "agg_int64")
396398

397399
snapshot.assert_match(sql, "out.sql")
@@ -400,7 +402,9 @@ def test_rank(scalar_types_df: bpd.DataFrame, snapshot):
400402
def test_shift(scalar_types_df: bpd.DataFrame, snapshot):
401403
col_name = "int64_col"
402404
bf_df = scalar_types_df[[col_name]]
403-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
405+
window = window_spec.WindowSpec(
406+
ordering=(ordering.ascending_over(col_name, nulls_last=False),)
407+
)
404408

405409
# Test lag
406410
lag_op = agg_exprs.UnaryAggregation(
@@ -440,7 +444,7 @@ def test_sum(scalar_types_df: bpd.DataFrame, snapshot):
440444
col_name = "int64_col"
441445
bf_df_int = scalar_types_df[[col_name]]
442446
agg_expr = agg_ops.SumOp().as_expr(col_name)
443-
window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),))
447+
window = window_spec.WindowSpec(ordering=(ordering.descending_over(col_name),))
444448
sql_window = _apply_unary_window_op(bf_df_int, agg_expr, window, "agg_int64")
445449
snapshot.assert_match(sql_window, "window_out.sql")
446450

0 commit comments

Comments
 (0)