diff --git a/bigframes/core/compile/sqlglot/expressions/numeric_ops.py b/bigframes/core/compile/sqlglot/expressions/numeric_ops.py index afc0d9d01c..b94ef6759d 100644 --- a/bigframes/core/compile/sqlglot/expressions/numeric_ops.py +++ b/bigframes/core/compile/sqlglot/expressions/numeric_ops.py @@ -77,6 +77,13 @@ def _(expr: TypedExpr) -> sge.Expression: return sge.func("ASINH", expr.expr) +@register_binary_op(ops.arctan2_op) +def _(left: TypedExpr, right: TypedExpr) -> sge.Expression: + left_expr = _coerce_bool_to_int(left) + right_expr = _coerce_bool_to_int(right) + return sge.func("ATAN2", left_expr, right_expr) + + @register_unary_op(ops.arctan_op) def _(expr: TypedExpr) -> sge.Expression: return sge.func("ATAN", expr.expr) diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan2/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan2/out.sql new file mode 100644 index 0000000000..d131828a98 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan2/out.sql @@ -0,0 +1,17 @@ +WITH `bfcte_0` AS ( + SELECT + `bool_col` AS `bfcol_0`, + `int64_col` AS `bfcol_1`, + `float64_col` AS `bfcol_2` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + ATAN2(`bfcol_1`, `bfcol_2`) AS `bfcol_6`, + ATAN2(CAST(`bfcol_0` AS INT64), `bfcol_2`) AS `bfcol_7` + FROM `bfcte_0` +) +SELECT + `bfcol_6` AS `int64_col`, + `bfcol_7` AS `bool_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/test_numeric_ops.py b/tests/unit/core/compile/sqlglot/expressions/test_numeric_ops.py index c66fe15c16..266ad1c938 100644 --- a/tests/unit/core/compile/sqlglot/expressions/test_numeric_ops.py +++ b/tests/unit/core/compile/sqlglot/expressions/test_numeric_ops.py @@ -55,6 +55,20 @@ def test_arcsinh(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_arctan2(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["int64_col", "float64_col", "bool_col"]] + + sql = utils._apply_ops_to_sql( + bf_df, + [ + ops.arctan2_op.as_expr("int64_col", "float64_col"), + ops.arctan2_op.as_expr("bool_col", "float64_col"), + ], + ["int64_col", "bool_col"], + ) + snapshot.assert_match(sql, "out.sql") + + def test_arctan(scalar_types_df: bpd.DataFrame, snapshot): col_name = "float64_col" bf_df = scalar_types_df[[col_name]]