File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
bigframes/core/compile/sqlglot/aggregations
tests/unit/core/compile/sqlglot/aggregations
snapshots/test_unary_compiler/test_all Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,17 @@ def compile(
3838 return UNARY_OP_REGISTRATION [op ](op , column , window = window )
3939
4040
41+ @UNARY_OP_REGISTRATION .register (agg_ops .AllOp )
42+ def _ (
43+ op : agg_ops .AllOp ,
44+ column : typed_expr .TypedExpr ,
45+ window : typing .Optional [window_spec .WindowSpec ] = None ,
46+ ) -> sge .Expression :
47+ # BQ will return null for empty column, result would be false in pandas.
48+ result = apply_window_if_present (sge .func ("LOGICAL_AND" , column .expr ), window )
49+ return sge .func ("IFNULL" , result , sge .true ())
50+
51+
4152@UNARY_OP_REGISTRATION .register (agg_ops .ApproxQuartilesOp )
4253def _ (
4354 op : agg_ops .ApproxQuartilesOp ,
Original file line number Diff line number Diff line change 1+ WITH ` bfcte_0` AS (
2+ SELECT
3+ ` bool_col` AS ` bfcol_0`
4+ FROM ` bigframes-dev` .` sqlglot_test` .` scalar_types`
5+ ), ` bfcte_1` AS (
6+ SELECT
7+ COALESCE(LOGICAL_AND(` bfcol_0` ), TRUE) AS ` bfcol_1`
8+ FROM ` bfcte_0`
9+ )
10+ SELECT
11+ ` bfcol_1` AS ` bool_col`
12+ FROM ` bfcte_1`
Original file line number Diff line number Diff line change @@ -63,6 +63,15 @@ def _apply_unary_window_op(
6363 return sql
6464
6565
66+ def test_all (scalar_types_df : bpd .DataFrame , snapshot ):
67+ col_name = "bool_col"
68+ bf_df = scalar_types_df [[col_name ]]
69+ agg_expr = agg_ops .AllOp ().as_expr (col_name )
70+ sql = _apply_unary_agg_ops (bf_df , [agg_expr ], [col_name ])
71+
72+ snapshot .assert_match (sql , "out.sql" )
73+
74+
6675def test_approx_quartiles (scalar_types_df : bpd .DataFrame , snapshot ):
6776 col_name = "int64_col"
6877 bf_df = scalar_types_df [[col_name ]]
You can’t perform that action at this time.
0 commit comments