Skip to content

Commit b32c125

Browse files
committed
refactor: test test_dataframe_rolling_closed_param
1 parent 2763b41 commit b32c125

File tree

4 files changed

+27
-12
lines changed
  • bigframes/core/compile/sqlglot
  • tests/unit/core/compile/sqlglot/snapshots/test_compile_window
    • test_compile_window_w_groupby_rolling
    • test_compile_window_w_range_rolling
    • test_compile_window_w_skips_nulls_op

4 files changed

+27
-12
lines changed

bigframes/core/compile/sqlglot/compiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ def compile_window(node: nodes.WindowOpNode, child: ir.SQLGlotIR) -> ir.SQLGlotI
356356
observation_count = windows.apply_window_if_present(
357357
sge.func("SUM", is_observation), window_spec
358358
)
359+
observation_count = sge.func(
360+
"COALESCE", observation_count, sge.convert(0)
361+
)
359362
else:
360363
# Operations like count treat even NULLs as valid observations
361364
# for the sake of min_periods notnull is just used to convert

tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_groupby_rolling/out.sql

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ WITH `bfcte_0` AS (
2222
SELECT
2323
*,
2424
CASE
25-
WHEN SUM(CAST(NOT `bfcol_7` IS NULL AS INT64)) OVER (
26-
PARTITION BY `bfcol_9`
27-
ORDER BY `bfcol_9` ASC NULLS LAST, `rowindex` ASC NULLS LAST
28-
ROWS BETWEEN 3 PRECEDING AND CURRENT ROW
25+
WHEN COALESCE(
26+
SUM(CAST(NOT `bfcol_7` IS NULL AS INT64)) OVER (
27+
PARTITION BY `bfcol_9`
28+
ORDER BY `bfcol_9` ASC NULLS LAST, `rowindex` ASC NULLS LAST
29+
ROWS BETWEEN 3 PRECEDING AND CURRENT ROW
30+
),
31+
0
2932
) < 3
3033
THEN NULL
3134
ELSE COALESCE(
@@ -42,10 +45,13 @@ WITH `bfcte_0` AS (
4245
SELECT
4346
*,
4447
CASE
45-
WHEN SUM(CAST(NOT `bfcol_8` IS NULL AS INT64)) OVER (
46-
PARTITION BY `bfcol_9`
47-
ORDER BY `bfcol_9` ASC NULLS LAST, `rowindex` ASC NULLS LAST
48-
ROWS BETWEEN 3 PRECEDING AND CURRENT ROW
48+
WHEN COALESCE(
49+
SUM(CAST(NOT `bfcol_8` IS NULL AS INT64)) OVER (
50+
PARTITION BY `bfcol_9`
51+
ORDER BY `bfcol_9` ASC NULLS LAST, `rowindex` ASC NULLS LAST
52+
ROWS BETWEEN 3 PRECEDING AND CURRENT ROW
53+
),
54+
0
4955
) < 3
5056
THEN NULL
5157
ELSE COALESCE(

tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ WITH `bfcte_0` AS (
66
SELECT
77
*,
88
CASE
9-
WHEN SUM(CAST(NOT `bfcol_1` IS NULL AS INT64)) OVER (
10-
ORDER BY UNIX_MICROS(`bfcol_0`) ASC NULLS LAST
11-
RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW
9+
WHEN COALESCE(
10+
SUM(CAST(NOT `bfcol_1` IS NULL AS INT64)) OVER (
11+
ORDER BY UNIX_MICROS(`bfcol_0`) ASC NULLS LAST
12+
RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW
13+
),
14+
0
1215
) < 1
1316
THEN NULL
1417
ELSE COALESCE(

tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_skips_nulls_op/out.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ WITH `bfcte_0` AS (
77
SELECT
88
*,
99
CASE
10-
WHEN SUM(CAST(NOT `int64_col` IS NULL AS INT64)) OVER (ORDER BY `rowindex` ASC NULLS LAST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) < 3
10+
WHEN COALESCE(
11+
SUM(CAST(NOT `int64_col` IS NULL AS INT64)) OVER (ORDER BY `rowindex` ASC NULLS LAST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW),
12+
0
13+
) < 3
1114
THEN NULL
1215
ELSE COALESCE(
1316
SUM(`int64_col`) OVER (ORDER BY `rowindex` ASC NULLS LAST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW),

0 commit comments

Comments
 (0)