Skip to content

Commit 371f0b5

Browse files
committed
dense_rank and rank doesn't support window framing clauses
1 parent 876d2a4 commit 371f0b5

File tree

2 files changed

+20
-4
lines changed
  • bigframes/core/compile/sqlglot/aggregations
  • tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_dense_rank

2 files changed

+20
-4
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,25 @@ def apply_window_if_present(
6464
if not window.bounds and not order:
6565
return sge.Window(this=value, partition_by=group_by)
6666

67+
# Ranking and navigation functions do not support window framing clauses.
68+
# See: https://cloud.google.com/bigquery/docs/reference/standard-sql/analytic-function-concepts#window-frame-clause
69+
no_frame_functions = {
70+
"RANK",
71+
"DENSE_RANK",
72+
"NTILE",
73+
"PERCENT_RANK",
74+
"CUME_DIST",
75+
"ROW_NUMBER",
76+
"LAG",
77+
"LEAD",
78+
"FIRST_VALUE",
79+
"LAST_VALUE",
80+
"NTH_VALUE",
81+
}
82+
func_name = value.sql_name().upper() if isinstance(value, sge.Func) else ""
83+
if not window.bounds and func_name in no_frame_functions:
84+
return sge.Window(this=value, partition_by=group_by, order=order)
85+
6786
kind = (
6887
"ROWS" if isinstance(window.bounds, window_spec.RowsWindowBounds) else "RANGE"
6988
)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ WITH `bfcte_0` AS (
66
), `bfcte_1` AS (
77
SELECT
88
*,
9-
DENSE_RANK() OVER (
10-
ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST
11-
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
12-
) AS `bfcol_4`
9+
DENSE_RANK() OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_4`
1310
FROM `bfcte_0`
1411
)
1512
SELECT

0 commit comments

Comments
 (0)