Skip to content

Commit 9f209a5

Browse files
committed
support bool
1 parent 7e3dd98 commit 9f209a5

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

bigframes/core/compile/sqlglot/expressions/numeric_ops.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def _(expr: TypedExpr) -> sge.Expression:
7979

8080
@register_binary_op(ops.arctan2_op)
8181
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
82-
return sge.func("ATAN2", left.expr, right.expr)
82+
left_expr = _coerce_bool_to_int(left)
83+
right_expr = _coerce_bool_to_int(right)
84+
return sge.func("ATAN2", left_expr, right_expr)
8385

8486

8587
@register_unary_op(ops.arctan_op)
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`int64_col` AS `bfcol_0`,
4-
`float64_col` AS `bfcol_1`
3+
`bool_col` AS `bfcol_0`,
4+
`int64_col` AS `bfcol_1`,
5+
`float64_col` AS `bfcol_2`
56
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
67
), `bfcte_1` AS (
78
SELECT
89
*,
9-
ATAN2(`bfcol_0`, `bfcol_1`) AS `bfcol_2`
10+
ATAN2(`bfcol_1`, `bfcol_2`) AS `bfcol_6`,
11+
ATAN2(CAST(`bfcol_0` AS INT64), `bfcol_2`) AS `bfcol_7`
1012
FROM `bfcte_0`
1113
)
1214
SELECT
13-
`bfcol_2` AS `int64_col`
15+
`bfcol_6` AS `int64_col`,
16+
`bfcol_7` AS `bool_col`
1417
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/test_numeric_ops.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,16 @@ def test_arcsinh(scalar_types_df: bpd.DataFrame, snapshot):
5656

5757

5858
def test_arctan2(scalar_types_df: bpd.DataFrame, snapshot):
59-
bf_df = scalar_types_df[["int64_col", "float64_col"]]
60-
sql = utils._apply_binary_op(bf_df, ops.arctan2_op, "int64_col", "float64_col")
61-
59+
bf_df = scalar_types_df[["int64_col", "float64_col", "bool_col"]]
60+
61+
sql = utils._apply_ops_to_sql(
62+
bf_df,
63+
[
64+
ops.arctan2_op.as_expr("int64_col", "float64_col"),
65+
ops.arctan2_op.as_expr("bool_col", "float64_col"),
66+
],
67+
["int64_col", "bool_col"],
68+
)
6269
snapshot.assert_match(sql, "out.sql")
6370

6471

0 commit comments

Comments
 (0)