From 4d915815a49d8c9e1fbc781205ace33c0f3ed788 Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Thu, 17 Jul 2025 22:46:09 +0000 Subject: [PATCH 1/6] chore: Migrate up to 5 scalar operators to SQLGlot Migrated cosh_op, tanh_op, arcsinh_op, arccosh_op, and arctanh_op scalar operators to SQLGlot. --- .../sqlglot/expressions/unary_compiler.py | 49 +++++++++++++++++++ .../test_unary_compiler/test_arccosh/out.sql | 13 +++++ .../test_unary_compiler/test_arcsinh/out.sql | 13 +++++ .../test_unary_compiler/test_arctanh/out.sql | 13 +++++ .../test_unary_compiler/test_cosh/out.sql | 13 +++++ .../test_unary_compiler/test_tanh/out.sql | 13 +++++ .../expressions/test_unary_compiler.py | 30 ++++++++++++ 7 files changed, 144 insertions(+) create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arcsinh/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_tanh/out.sql diff --git a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py index 1fc074e2ef..3700c19e34 100644 --- a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py @@ -38,6 +38,19 @@ def compile(op: ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return UNARY_OP_REGISTRATION[op](op, expr) +@UNARY_OP_REGISTRATION.register(ops.arccosh_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Case( + ifs=[ + sge.If( + this=expr.expr < sge.convert(1), + true=sge.func("IEEE_DIVIDE", sge.convert(0), sge.convert(0)), + ) + ], + default=sge.func("ACOSH", expr.expr), + ) + + @UNARY_OP_REGISTRATION.register(ops.arccos_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.Case( @@ -64,11 +77,29 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: ) +@UNARY_OP_REGISTRATION.register(ops.arcsinh_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.func("ASINH", expr.expr) + + @UNARY_OP_REGISTRATION.register(ops.arctan_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.func("ATAN", expr.expr) +@UNARY_OP_REGISTRATION.register(ops.arctanh_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Case( + ifs=[ + sge.If( + this=sge.func("ABS", expr.expr) > sge.convert(1), + true=sge.func("IEEE_DIVIDE", sge.convert(0), sge.convert(0)), + ) + ], + default=sge.func("ATANH", expr.expr), + ) + + @UNARY_OP_REGISTRATION.register(ops.ArrayToStringOp) def _(op: ops.ArrayToStringOp, expr: TypedExpr) -> sge.Expression: return sge.ArrayToString(this=expr.expr, expression=f"'{op.delimiter}'") @@ -116,6 +147,19 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.func("COS", expr.expr) +@UNARY_OP_REGISTRATION.register(ops.cosh_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Case( + ifs=[ + sge.If( + this=sge.func("ABS", expr.expr) > sge.convert(709.78), + true=sge.func("IEEE_DIVIDE", sge.convert(1), sge.convert(0)), + ) + ], + default=sge.func("COSH", expr.expr), + ) + + @UNARY_OP_REGISTRATION.register(ops.hash_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.func("FARM_FINGERPRINT", expr.expr) @@ -154,6 +198,11 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.func("TAN", expr.expr) +@UNARY_OP_REGISTRATION.register(ops.tanh_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.func("TANH", expr.expr) + + # JSON Ops @UNARY_OP_REGISTRATION.register(ops.JSONExtract) def _(op: ops.JSONExtract, expr: TypedExpr) -> sge.Expression: diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql new file mode 100644 index 0000000000..a6addefec9 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + CASE WHEN `bfcol_0` < 1 THEN IEEE_DIVIDE(0, 0) ELSE ACOSH(`bfcol_0`) END AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arcsinh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arcsinh/out.sql new file mode 100644 index 0000000000..6313e80e5f --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arcsinh/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + ASINH(`bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql new file mode 100644 index 0000000000..d843c3fb1c --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + CASE WHEN ABS(`bfcol_0`) > 1 THEN IEEE_DIVIDE(0, 0) ELSE ATANH(`bfcol_0`) END AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql new file mode 100644 index 0000000000..a6fe474e8b --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + CASE WHEN ABS(`bfcol_0`) > 709.78 THEN IEEE_DIVIDE(1, 0) ELSE COSH(`bfcol_0`) END AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_tanh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_tanh/out.sql new file mode 100644 index 0000000000..5d1a5a5320 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_tanh/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + TANH(`bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py index 6449f179ab..1e101d2809 100644 --- a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py +++ b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py @@ -34,6 +34,12 @@ def _apply_unary_op(obj: bpd.DataFrame, op: ops.UnaryOp, arg: str) -> str: return sql +def test_arccosh(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.arccosh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + def test_arccos(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.arccos_op, "float64_col") @@ -48,6 +54,12 @@ def test_arcsin(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_arcsinh(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.arcsinh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + def test_arctan(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.arctan_op, "float64_col") @@ -55,6 +67,12 @@ def test_arctan(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_arctanh(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.arctanh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + def test_array_to_string(repeated_types_df: bpd.DataFrame, snapshot): bf_df = repeated_types_df[["string_list_col"]] sql = _apply_unary_op(bf_df, ops.ArrayToStringOp(delimiter="."), "string_list_col") @@ -90,6 +108,12 @@ def test_cos(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_cosh(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.cosh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + def test_hash(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["string_col"]] sql = _apply_unary_op(bf_df, ops.hash_op, "string_col") @@ -132,6 +156,12 @@ def test_tan(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_tanh(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.tanh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + def test_json_extract(json_types_df: bpd.DataFrame, snapshot): bf_df = json_types_df[["json_col"]] sql = _apply_unary_op(bf_df, ops.JSONExtract(json_path="$"), "json_col") From c8bae7650d55fb9d9a2e32bc7942e830347bc29e Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Thu, 17 Jul 2025 23:22:31 +0000 Subject: [PATCH 2/6] chore: Migrate up to 5 scalar operators to SQLGlot Migrated operators: - abs_op - capitalize_op - ceil_op - date_op - day_op --- .../sqlglot/expressions/unary_compiler.py | 25 ++++++++++++++++ .../test_unary_compiler/test_abs/out.sql | 13 ++++++++ .../test_capitalize/out.sql | 13 ++++++++ .../test_unary_compiler/test_ceil/out.sql | 13 ++++++++ .../test_unary_compiler/test_date/out.sql | 13 ++++++++ .../test_unary_compiler/test_day/out.sql | 13 ++++++++ .../expressions/test_unary_compiler.py | 30 +++++++++++++++++++ 7 files changed, 120 insertions(+) create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_abs/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_capitalize/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_ceil/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_date/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_day/out.sql diff --git a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py index 3700c19e34..030fdc03b6 100644 --- a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py @@ -38,6 +38,11 @@ def compile(op: ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return UNARY_OP_REGISTRATION[op](op, expr) +@UNARY_OP_REGISTRATION.register(ops.abs_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Abs(this=expr.expr) + + @UNARY_OP_REGISTRATION.register(ops.arccosh_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.Case( @@ -142,6 +147,16 @@ def _(op: ops.ArraySliceOp, expr: TypedExpr) -> sge.Expression: return sge.array(selected_elements) +@UNARY_OP_REGISTRATION.register(ops.capitalize_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Initcap(this=expr.expr) + + +@UNARY_OP_REGISTRATION.register(ops.ceil_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Ceil(this=expr.expr) + + @UNARY_OP_REGISTRATION.register(ops.cos_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.func("COS", expr.expr) @@ -160,6 +175,16 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: ) +@UNARY_OP_REGISTRATION.register(ops.date_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Date(this=expr.expr) + + +@UNARY_OP_REGISTRATION.register(ops.day_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Extract(this=sge.Identifier(this="DAY"), expression=expr.expr) + + @UNARY_OP_REGISTRATION.register(ops.hash_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.func("FARM_FINGERPRINT", expr.expr) diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_abs/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_abs/out.sql new file mode 100644 index 0000000000..6f315f8113 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_abs/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + ABS(`bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_capitalize/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_capitalize/out.sql new file mode 100644 index 0000000000..7af1708347 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_capitalize/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `string_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + INITCAP(`bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `string_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_ceil/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_ceil/out.sql new file mode 100644 index 0000000000..0959f3a0ad --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_ceil/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + CEIL(`bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_date/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_date/out.sql new file mode 100644 index 0000000000..615a4a92bb --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_date/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `timestamp_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + DATE(`bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `timestamp_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_day/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_day/out.sql new file mode 100644 index 0000000000..460823fa20 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_day/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `timestamp_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + EXTRACT(DAY FROM `bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `timestamp_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py index 1e101d2809..7e9d49d3d4 100644 --- a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py +++ b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py @@ -73,6 +73,36 @@ def test_arctanh(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_abs(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.abs_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + +def test_capitalize(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["string_col"]] + sql = _apply_unary_op(bf_df, ops.capitalize_op, "string_col") + snapshot.assert_match(sql, "out.sql") + + +def test_ceil(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.ceil_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + +def test_date(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["timestamp_col"]] + sql = _apply_unary_op(bf_df, ops.date_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") + + +def test_day(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["timestamp_col"]] + sql = _apply_unary_op(bf_df, ops.day_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") + + def test_array_to_string(repeated_types_df: bpd.DataFrame, snapshot): bf_df = repeated_types_df[["string_list_col"]] sql = _apply_unary_op(bf_df, ops.ArrayToStringOp(delimiter="."), "string_list_col") From a193ef9e1f75e701b631849550fe820a7353d0ed Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Mon, 21 Jul 2025 22:39:35 +0000 Subject: [PATCH 3/6] switch _INF _NAN --- .../core/compile/sqlglot/expressions/unary_compiler.py | 6 +++--- .../snapshots/test_unary_compiler/test_arccosh/out.sql | 2 +- .../snapshots/test_unary_compiler/test_arctanh/out.sql | 2 +- .../snapshots/test_unary_compiler/test_cosh/out.sql | 6 +++++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py index 030fdc03b6..ec0c07346d 100644 --- a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py @@ -49,7 +49,7 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: ifs=[ sge.If( this=expr.expr < sge.convert(1), - true=sge.func("IEEE_DIVIDE", sge.convert(0), sge.convert(0)), + true=_NAN, ) ], default=sge.func("ACOSH", expr.expr), @@ -98,7 +98,7 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: ifs=[ sge.If( this=sge.func("ABS", expr.expr) > sge.convert(1), - true=sge.func("IEEE_DIVIDE", sge.convert(0), sge.convert(0)), + true=_NAN, ) ], default=sge.func("ATANH", expr.expr), @@ -168,7 +168,7 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: ifs=[ sge.If( this=sge.func("ABS", expr.expr) > sge.convert(709.78), - true=sge.func("IEEE_DIVIDE", sge.convert(1), sge.convert(0)), + true=_INF, ) ], default=sge.func("COSH", expr.expr), diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql index a6addefec9..5272e4a6a8 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arccosh/out.sql @@ -5,7 +5,7 @@ WITH `bfcte_0` AS ( ), `bfcte_1` AS ( SELECT *, - CASE WHEN `bfcol_0` < 1 THEN IEEE_DIVIDE(0, 0) ELSE ACOSH(`bfcol_0`) END AS `bfcol_1` + CASE WHEN `bfcol_0` < 1 THEN CAST('NaN' AS FLOAT64) ELSE ACOSH(`bfcol_0`) END AS `bfcol_1` FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql index d843c3fb1c..39b5f565fe 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_arctanh/out.sql @@ -5,7 +5,7 @@ WITH `bfcte_0` AS ( ), `bfcte_1` AS ( SELECT *, - CASE WHEN ABS(`bfcol_0`) > 1 THEN IEEE_DIVIDE(0, 0) ELSE ATANH(`bfcol_0`) END AS `bfcol_1` + CASE WHEN ABS(`bfcol_0`) > 1 THEN CAST('NaN' AS FLOAT64) ELSE ATANH(`bfcol_0`) END AS `bfcol_1` FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql index a6fe474e8b..f44dfaac41 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_cosh/out.sql @@ -5,7 +5,11 @@ WITH `bfcte_0` AS ( ), `bfcte_1` AS ( SELECT *, - CASE WHEN ABS(`bfcol_0`) > 709.78 THEN IEEE_DIVIDE(1, 0) ELSE COSH(`bfcol_0`) END AS `bfcol_1` + CASE + WHEN ABS(`bfcol_0`) > 709.78 + THEN CAST('Infinity' AS FLOAT64) + ELSE COSH(`bfcol_0`) + END AS `bfcol_1` FROM `bfcte_0` ) SELECT From 925ceb49596278d6747b83b895c1f97b5ac4b729 Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Thu, 17 Jul 2025 23:30:06 +0000 Subject: [PATCH 4/6] chore: Migrate up to 5 scalar operators to SQLGlot Migrated operators: - dayofweek_op - dayofyear_op - exp_op - expm1_op - floor_op --- .../sqlglot/expressions/unary_compiler.py | 41 +++++++++++++++++++ .../test_dayofweek/out.sql | 13 ++++++ .../test_dayofyear/out.sql | 13 ++++++ .../test_unary_compiler/test_exp/out.sql | 13 ++++++ .../test_unary_compiler/test_expm1/out.sql | 13 ++++++ .../test_unary_compiler/test_floor/out.sql | 13 ++++++ .../expressions/test_unary_compiler.py | 30 ++++++++++++++ 7 files changed, 136 insertions(+) create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofyear/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql create mode 100644 tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_floor/out.sql diff --git a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py index ec0c07346d..f9dd8634c3 100644 --- a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py @@ -185,6 +185,47 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.Extract(this=sge.Identifier(this="DAY"), expression=expr.expr) +@UNARY_OP_REGISTRATION.register(ops.dayofweek_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Extract(this=sge.Identifier(this="DAYOFWEEK"), expression=expr.expr) + + +@UNARY_OP_REGISTRATION.register(ops.dayofyear_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Extract(this=sge.Identifier(this="DAYOFYEAR"), expression=expr.expr) + + +@UNARY_OP_REGISTRATION.register(ops.exp_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Case( + ifs=[ + sge.If( + this=expr.expr > sge.convert(709.78), + true=sge.func("IEEE_DIVIDE", sge.convert(1), sge.convert(0)), + ) + ], + default=sge.func("EXP", expr.expr), + ) + + +@UNARY_OP_REGISTRATION.register(ops.expm1_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Case( + ifs=[ + sge.If( + this=expr.expr > sge.convert(709.78), + true=sge.func("IEEE_DIVIDE", sge.convert(1), sge.convert(0)), + ) + ], + default=sge.func("EXP", expr.expr), + ) - sge.convert(1) + + +@UNARY_OP_REGISTRATION.register(ops.floor_op) +def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: + return sge.Floor(this=expr.expr) + + @UNARY_OP_REGISTRATION.register(ops.hash_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.func("FARM_FINGERPRINT", expr.expr) diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql new file mode 100644 index 0000000000..d389172fda --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `timestamp_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + EXTRACT(DAYOFWEEK FROM `bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `timestamp_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofyear/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofyear/out.sql new file mode 100644 index 0000000000..4b60bcc4ca --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofyear/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `timestamp_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + EXTRACT(DAYOFYEAR FROM `bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `timestamp_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql new file mode 100644 index 0000000000..9a802b82c8 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + CASE WHEN `bfcol_0` > 709.78 THEN IEEE_DIVIDE(1, 0) ELSE EXP(`bfcol_0`) END AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql new file mode 100644 index 0000000000..6a7428b4fa --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + CASE WHEN `bfcol_0` > 709.78 THEN IEEE_DIVIDE(1, 0) ELSE EXP(`bfcol_0`) END - 1 AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_floor/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_floor/out.sql new file mode 100644 index 0000000000..56be1019e5 --- /dev/null +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_floor/out.sql @@ -0,0 +1,13 @@ +WITH `bfcte_0` AS ( + SELECT + `float64_col` AS `bfcol_0` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` +), `bfcte_1` AS ( + SELECT + *, + FLOOR(`bfcol_0`) AS `bfcol_1` + FROM `bfcte_0` +) +SELECT + `bfcol_1` AS `float64_col` +FROM `bfcte_1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py index 7e9d49d3d4..41dff04ab1 100644 --- a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py +++ b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py @@ -103,6 +103,36 @@ def test_day(scalar_types_df: bpd.DataFrame, snapshot): snapshot.assert_match(sql, "out.sql") +def test_dayofweek(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["timestamp_col"]] + sql = _apply_unary_op(bf_df, ops.dayofweek_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") + + +def test_dayofyear(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["timestamp_col"]] + sql = _apply_unary_op(bf_df, ops.dayofyear_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") + + +def test_exp(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.exp_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + +def test_expm1(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.expm1_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + +def test_floor(scalar_types_df: bpd.DataFrame, snapshot): + bf_df = scalar_types_df[["float64_col"]] + sql = _apply_unary_op(bf_df, ops.floor_op, "float64_col") + snapshot.assert_match(sql, "out.sql") + + def test_array_to_string(repeated_types_df: bpd.DataFrame, snapshot): bf_df = repeated_types_df[["string_list_col"]] sql = _apply_unary_op(bf_df, ops.ArrayToStringOp(delimiter="."), "string_list_col") From fb5e036bd78051ad7c76e03b76ad131279f5e60e Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Mon, 21 Jul 2025 22:42:15 +0000 Subject: [PATCH 5/6] switch _INF _FLOAT64_EXP_BOUND --- .../core/compile/sqlglot/expressions/unary_compiler.py | 8 ++++---- .../snapshots/test_unary_compiler/test_exp/out.sql | 6 +++++- .../snapshots/test_unary_compiler/test_expm1/out.sql | 6 +++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py index f9dd8634c3..7b761bee5e 100644 --- a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py @@ -200,8 +200,8 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.Case( ifs=[ sge.If( - this=expr.expr > sge.convert(709.78), - true=sge.func("IEEE_DIVIDE", sge.convert(1), sge.convert(0)), + this=expr.expr > _FLOAT64_EXP_BOUND, + true=_INF, ) ], default=sge.func("EXP", expr.expr), @@ -213,8 +213,8 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: return sge.Case( ifs=[ sge.If( - this=expr.expr > sge.convert(709.78), - true=sge.func("IEEE_DIVIDE", sge.convert(1), sge.convert(0)), + this=expr.expr > _FLOAT64_EXP_BOUND, + true=_INF, ) ], default=sge.func("EXP", expr.expr), diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql index 9a802b82c8..6afa3f85a5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_exp/out.sql @@ -5,7 +5,11 @@ WITH `bfcte_0` AS ( ), `bfcte_1` AS ( SELECT *, - CASE WHEN `bfcol_0` > 709.78 THEN IEEE_DIVIDE(1, 0) ELSE EXP(`bfcol_0`) END AS `bfcol_1` + CASE + WHEN `bfcol_0` > 709.78 + THEN CAST('Infinity' AS FLOAT64) + ELSE EXP(`bfcol_0`) + END AS `bfcol_1` FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql index 6a7428b4fa..f3768deb4a 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_expm1/out.sql @@ -5,7 +5,11 @@ WITH `bfcte_0` AS ( ), `bfcte_1` AS ( SELECT *, - CASE WHEN `bfcol_0` > 709.78 THEN IEEE_DIVIDE(1, 0) ELSE EXP(`bfcol_0`) END - 1 AS `bfcol_1` + CASE + WHEN `bfcol_0` > 709.78 + THEN CAST('Infinity' AS FLOAT64) + ELSE EXP(`bfcol_0`) + END - 1 AS `bfcol_1` FROM `bfcte_0` ) SELECT From d7b2f2e51bf464e03067cd9167411f0863285448 Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Tue, 22 Jul 2025 17:18:56 +0000 Subject: [PATCH 6/6] address comments --- .../compile/sqlglot/expressions/unary_compiler.py | 5 ++++- .../test_unary_compiler/test_dayofweek/out.sql | 2 +- .../sqlglot/expressions/test_unary_compiler.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py index 7b761bee5e..714c348f0b 100644 --- a/bigframes/core/compile/sqlglot/expressions/unary_compiler.py +++ b/bigframes/core/compile/sqlglot/expressions/unary_compiler.py @@ -187,7 +187,10 @@ def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: @UNARY_OP_REGISTRATION.register(ops.dayofweek_op) def _(op: ops.base_ops.UnaryOp, expr: TypedExpr) -> sge.Expression: - return sge.Extract(this=sge.Identifier(this="DAYOFWEEK"), expression=expr.expr) + # Adjust the 1-based day-of-week index (from SQL) to a 0-based index. + return sge.Extract( + this=sge.Identifier(this="DAYOFWEEK"), expression=expr.expr + ) - sge.convert(1) @UNARY_OP_REGISTRATION.register(ops.dayofyear_op) diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql index d389172fda..e6c17587d0 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_unary_compiler/test_dayofweek/out.sql @@ -5,7 +5,7 @@ WITH `bfcte_0` AS ( ), `bfcte_1` AS ( SELECT *, - EXTRACT(DAYOFWEEK FROM `bfcol_0`) AS `bfcol_1` + EXTRACT(DAYOFWEEK FROM `bfcol_0`) - 1 AS `bfcol_1` FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py index 41dff04ab1..7421c4c46f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py +++ b/tests/unit/core/compile/sqlglot/expressions/test_unary_compiler.py @@ -37,6 +37,7 @@ def _apply_unary_op(obj: bpd.DataFrame, op: ops.UnaryOp, arg: str) -> str: def test_arccosh(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.arccosh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") @@ -57,6 +58,7 @@ def test_arcsin(scalar_types_df: bpd.DataFrame, snapshot): def test_arcsinh(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.arcsinh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") @@ -70,18 +72,21 @@ def test_arctan(scalar_types_df: bpd.DataFrame, snapshot): def test_arctanh(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.arctanh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") def test_abs(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.abs_op, "float64_col") + snapshot.assert_match(sql, "out.sql") def test_capitalize(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["string_col"]] sql = _apply_unary_op(bf_df, ops.capitalize_op, "string_col") + snapshot.assert_match(sql, "out.sql") @@ -94,42 +99,49 @@ def test_ceil(scalar_types_df: bpd.DataFrame, snapshot): def test_date(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["timestamp_col"]] sql = _apply_unary_op(bf_df, ops.date_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") def test_day(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["timestamp_col"]] sql = _apply_unary_op(bf_df, ops.day_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") def test_dayofweek(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["timestamp_col"]] sql = _apply_unary_op(bf_df, ops.dayofweek_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") def test_dayofyear(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["timestamp_col"]] sql = _apply_unary_op(bf_df, ops.dayofyear_op, "timestamp_col") + snapshot.assert_match(sql, "out.sql") def test_exp(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.exp_op, "float64_col") + snapshot.assert_match(sql, "out.sql") def test_expm1(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.expm1_op, "float64_col") + snapshot.assert_match(sql, "out.sql") def test_floor(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.floor_op, "float64_col") + snapshot.assert_match(sql, "out.sql") @@ -171,6 +183,7 @@ def test_cos(scalar_types_df: bpd.DataFrame, snapshot): def test_cosh(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.cosh_op, "float64_col") + snapshot.assert_match(sql, "out.sql") @@ -219,6 +232,7 @@ def test_tan(scalar_types_df: bpd.DataFrame, snapshot): def test_tanh(scalar_types_df: bpd.DataFrame, snapshot): bf_df = scalar_types_df[["float64_col"]] sql = _apply_unary_op(bf_df, ops.tanh_op, "float64_col") + snapshot.assert_match(sql, "out.sql")