Skip to content

Commit 3e7879d

Browse files
committed
chore: Migrate arctan2_op operator to SQLGlot
Migrated the arctan2_op operator to SQLGlot.
1 parent ef5e83a commit 3e7879d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def _(expr: TypedExpr) -> sge.Expression:
7777
return sge.func("ASINH", expr.expr)
7878

7979

80+
@register_binary_op(ops.arctan2_op)
81+
def _(left: TypedExpr, right: TypedExpr) -> sge.Expression:
82+
return sge.func("ATAN2", left.expr, right.expr)
83+
84+
8085
@register_unary_op(ops.arctan_op)
8186
def _(expr: TypedExpr) -> sge.Expression:
8287
return sge.func("ATAN", expr.expr)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`int64_col` AS `bfcol_0`,
4+
`float64_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
ATAN2(`bfcol_0`, `bfcol_1`) AS `bfcol_2`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_2` AS `int64_col`
14+
FROM `bfcte_1`

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ def test_arcsinh(scalar_types_df: bpd.DataFrame, snapshot):
5555
snapshot.assert_match(sql, "out.sql")
5656

5757

58+
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+
62+
snapshot.assert_match(sql, "out.sql")
63+
64+
5865
def test_arctan(scalar_types_df: bpd.DataFrame, snapshot):
5966
col_name = "float64_col"
6067
bf_df = scalar_types_df[[col_name]]

0 commit comments

Comments
 (0)