From 2bea5ee4f531bda4a95a3601910829b0c1c3b94c Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Thu, 20 Nov 2025 20:58:30 +0000 Subject: [PATCH 1/2] chore: raise error explicitly for AllOp with windows --- bigframes/core/compile/ibis_compiler/aggregate_compiler.py | 3 +++ bigframes/core/compile/sqlglot/aggregations/unary_compiler.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/bigframes/core/compile/ibis_compiler/aggregate_compiler.py b/bigframes/core/compile/ibis_compiler/aggregate_compiler.py index 0106b150e2..b675a08ade 100644 --- a/bigframes/core/compile/ibis_compiler/aggregate_compiler.py +++ b/bigframes/core/compile/ibis_compiler/aggregate_compiler.py @@ -633,6 +633,9 @@ def _( column: ibis_types.Column, window=None, ) -> ibis_types.BooleanValue: + if window is not None: + raise NotImplementedError("AllOp with windowing is not supported.") + # BQ will return null for empty column, result would be false in pandas. result = _apply_window_if_present(_is_true(column).all(), window) literal = ibis_types.literal(True) diff --git a/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py b/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py index e2bd6b8382..8d8488bad8 100644 --- a/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py @@ -44,6 +44,9 @@ def _( column: typed_expr.TypedExpr, window: typing.Optional[window_spec.WindowSpec] = None, ) -> sge.Expression: + # if window is not None: + # raise NotImplementedError("AllOp with windowing is not supported.") + # BQ will return null for empty column, result would be false in pandas. result = apply_window_if_present(sge.func("LOGICAL_AND", column.expr), window) return sge.func("IFNULL", result, sge.true()) From 5ed6af10dfdf14f739d4a23175c98854b08a4459 Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Thu, 20 Nov 2025 21:47:47 +0000 Subject: [PATCH 2/2] apply to sqlglot compiler too --- .../sqlglot/aggregations/unary_compiler.py | 4 ++-- .../test_all/window_out.sql | 13 ------------ .../test_all/window_partition_out.sql | 14 ------------- .../aggregations/test_unary_compiler.py | 20 +++++++------------ 4 files changed, 9 insertions(+), 42 deletions(-) delete mode 100644 tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_out.sql delete mode 100644 tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_partition_out.sql diff --git a/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py b/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py index 8d8488bad8..034ced66b3 100644 --- a/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/aggregations/unary_compiler.py @@ -44,8 +44,8 @@ def _( column: typed_expr.TypedExpr, window: typing.Optional[window_spec.WindowSpec] = None, ) -> sge.Expression: - # if window is not None: - # raise NotImplementedError("AllOp with windowing is not supported.") + if window is not None: + raise NotImplementedError("AllOp with windowing is not supported.") # BQ will return null for empty column, result would be false in pandas. result = apply_window_if_present(sge.func("LOGICAL_AND", column.expr), window) diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_out.sql deleted file mode 100644 index 829e5a8836..0000000000 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_out.sql +++ /dev/null @@ -1,13 +0,0 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` -), `bfcte_1` AS ( - SELECT - *, - COALESCE(LOGICAL_AND(`bool_col`) OVER (), TRUE) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `agg_bool` -FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_partition_out.sql deleted file mode 100644 index 23357817c1..0000000000 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/window_partition_out.sql +++ /dev/null @@ -1,14 +0,0 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col`, - `string_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` -), `bfcte_1` AS ( - SELECT - *, - COALESCE(LOGICAL_AND(`bool_col`) OVER (PARTITION BY `string_col`), TRUE) AS `bfcol_2` - FROM `bfcte_0` -) -SELECT - `bfcol_2` AS `agg_bool` -FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/test_unary_compiler.py b/tests/unit/core/compile/sqlglot/aggregations/test_unary_compiler.py index ab9f7febbf..37a46638fd 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/test_unary_compiler.py +++ b/tests/unit/core/compile/sqlglot/aggregations/test_unary_compiler.py @@ -72,20 +72,14 @@ def test_all(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") - # Window tests - window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),)) - sql_window = _apply_unary_window_op(bf_df, agg_expr, window, "agg_bool") - snapshot.assert_match(sql_window, "window_out.sql") - bf_df_str = scalar_types_df[[col_name, "string_col"]] - window_partition = window_spec.WindowSpec( - grouping_keys=(expression.deref("string_col"),), - ordering=(ordering.descending_over(col_name),), - ) - sql_window_partition = _apply_unary_window_op( - bf_df_str, agg_expr, window_partition, "agg_bool" - ) - snapshot.assert_match(sql_window_partition, "window_partition_out.sql") +def test_all_raises_error_with_window(scalar_types_df: bpd.DataFrame): + col_name = "bool_col" + bf_df = scalar_types_df[[col_name]] + agg_expr = agg_ops.AllOp().as_expr(col_name) + window = window_spec.WindowSpec(ordering=(ordering.ascending_over(col_name),)) + with pytest.raises(NotImplementedError): + _apply_unary_window_op(bf_df, agg_expr, window, "agg_bool") def test_any(scalar_types_df: bpd.DataFrame, snapshot):