Skip to content

Commit 3275761

Browse files
authored
refactor: switch RowNumber to 0-based indexing in sqlglot compiler (#2292)
This change aims to fix the tests failing in #2248 because of a 1-based indexing error. Fixes internal issue 417774347 🦕
1 parent b487cf1 commit 3275761

File tree

5 files changed

+10
-10
lines changed
  • bigframes/core/compile/sqlglot/aggregations
  • tests/unit/core/compile/sqlglot
    • aggregations/snapshots/test_nullary_compiler
    • snapshots/test_compile_concat

5 files changed

+10
-10
lines changed

bigframes/core/compile/sqlglot/aggregations/nullary_compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ def _(
4949
result: sge.Expression = sge.func("ROW_NUMBER")
5050
if window is None:
5151
# ROW_NUMBER always needs an OVER clause.
52-
return sge.Window(this=result)
53-
return apply_window_if_present(result, window, include_framing_clauses=False)
52+
return sge.Window(this=result) - 1
53+
return apply_window_if_present(result, window, include_framing_clauses=False) - 1

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ WITH `bfcte_0` AS (
1919
), `bfcte_1` AS (
2020
SELECT
2121
*,
22-
ROW_NUMBER() OVER () AS `bfcol_32`
22+
ROW_NUMBER() OVER () - 1 AS `bfcol_32`
2323
FROM `bfcte_0`
2424
)
2525
SELECT

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number_with_window/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-
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) AS `bfcol_1`
8+
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `bfcol_1`
99
FROM `bfcte_0`
1010
)
1111
SELECT

tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ WITH `bfcte_1` AS (
77
), `bfcte_3` AS (
88
SELECT
99
*,
10-
ROW_NUMBER() OVER () AS `bfcol_7`
10+
ROW_NUMBER() OVER () - 1 AS `bfcol_7`
1111
FROM `bfcte_1`
1212
), `bfcte_5` AS (
1313
SELECT
@@ -32,7 +32,7 @@ WITH `bfcte_1` AS (
3232
), `bfcte_2` AS (
3333
SELECT
3434
*,
35-
ROW_NUMBER() OVER () AS `bfcol_22`
35+
ROW_NUMBER() OVER () - 1 AS `bfcol_22`
3636
FROM `bfcte_0`
3737
), `bfcte_4` AS (
3838
SELECT

tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ WITH `bfcte_2` AS (
66
), `bfcte_6` AS (
77
SELECT
88
*,
9-
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) AS `bfcol_4`
9+
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `bfcol_4`
1010
FROM `bfcte_2`
1111
), `bfcte_10` AS (
1212
SELECT
@@ -35,7 +35,7 @@ WITH `bfcte_2` AS (
3535
), `bfcte_8` AS (
3636
SELECT
3737
*,
38-
ROW_NUMBER() OVER () AS `bfcol_15`
38+
ROW_NUMBER() OVER () - 1 AS `bfcol_15`
3939
FROM `bfcte_4`
4040
), `bfcte_12` AS (
4141
SELECT
@@ -57,7 +57,7 @@ WITH `bfcte_2` AS (
5757
), `bfcte_5` AS (
5858
SELECT
5959
*,
60-
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) AS `bfcol_25`
60+
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `bfcol_25`
6161
FROM `bfcte_1`
6262
), `bfcte_9` AS (
6363
SELECT
@@ -86,7 +86,7 @@ WITH `bfcte_2` AS (
8686
), `bfcte_7` AS (
8787
SELECT
8888
*,
89-
ROW_NUMBER() OVER () AS `bfcol_36`
89+
ROW_NUMBER() OVER () - 1 AS `bfcol_36`
9090
FROM `bfcte_3`
9191
), `bfcte_11` AS (
9292
SELECT

0 commit comments

Comments
 (0)