Skip to content

Commit 4ad65b6

Browse files
committed
refactor: fix groupby.GroupBy.first doctest for sqlglot
1 parent 173b83d commit 4ad65b6

File tree

2 files changed

+22
-2
lines changed
  • bigframes/core/compile/sqlglot
  • tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_groupby_rolling

2 files changed

+22
-2
lines changed

bigframes/core/compile/sqlglot/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def compile_window(node: nodes.WindowOpNode, child: ir.SQLGlotIR) -> ir.SQLGlotI
378378
window_op = sge.Case(ifs=when_expressions, default=window_op)
379379

380380
# TODO: check if we can directly window the expression.
381-
result = child.window(
381+
result = result.window(
382382
window_op=window_op,
383383
output_column_id=cdef.id.sql,
384384
)

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,32 @@ WITH `bfcte_0` AS (
1212
`int64_col` AS `bfcol_8`,
1313
`bool_col` AS `bfcol_9`
1414
FROM `bfcte_0`
15-
), `bfcte_3` AS (
15+
), `bfcte_2` AS (
1616
SELECT
1717
*
1818
FROM `bfcte_1`
1919
WHERE
2020
NOT `bfcol_9` IS NULL
21+
), `bfcte_3` AS (
22+
SELECT
23+
*,
24+
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
29+
) < 3
30+
THEN NULL
31+
ELSE COALESCE(
32+
SUM(CAST(`bfcol_7` AS INT64)) OVER (
33+
PARTITION BY `bfcol_9`
34+
ORDER BY `bfcol_9` ASC NULLS LAST, `rowindex` ASC NULLS LAST
35+
ROWS BETWEEN 3 PRECEDING AND CURRENT ROW
36+
),
37+
0
38+
)
39+
END AS `bfcol_15`
40+
FROM `bfcte_2`
2141
), `bfcte_4` AS (
2242
SELECT
2343
*,

0 commit comments

Comments
 (0)