Skip to content

Commit 542eab7

Browse files
committed
reuse the testing utils.py method
1 parent 6c81445 commit 542eab7

File tree

6 files changed

+11
-34
lines changed

6 files changed

+11
-34
lines changed

bigframes/testing/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,20 @@ def _apply_unary_ops(
467467
return sql
468468

469469

470-
def _apply_binary_op(
470+
def _apply_nary_op(
471471
obj: bpd.DataFrame,
472472
op: ops.BinaryOp,
473-
l_arg: str,
474-
r_arg: Union[str, ex.Expression],
473+
*args: Union[str, ex.Expression],
475474
) -> str:
476-
"""Applies a binary op to the given DataFrame and return the SQL representing
475+
"""Applies a nary op to the given DataFrame and return the SQL representing
477476
the resulting DataFrame."""
478477
array_value = obj._block.expr
479-
op_expr = op.as_expr(l_arg, r_arg)
478+
op_expr = op.as_expr(*args)
480479
result, col_ids = array_value.compute_values([op_expr])
481480

482481
# Rename columns for deterministic golden SQL results.
483482
assert len(col_ids) == 1
484-
result = result.rename_columns({col_ids[0]: l_arg}).select_columns([l_arg])
483+
result = result.rename_columns({col_ids[0]: args[0]}).select_columns([args[0]])
485484

486485
sql = result.session._executor.to_sql(result, enable_cache=False)
487486
return sql

tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_op/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ WITH `bfcte_0` AS (
1717
FROM `bfcte_0`
1818
)
1919
SELECT
20-
`bfcol_4` AS `result_col`
20+
`bfcol_4` AS `bool_col`
2121
FROM `bfcte_1`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_is_in(scalar_types_df: bpd.DataFrame, snapshot):
4646

4747
def test_eq_null_match(scalar_types_df: bpd.DataFrame, snapshot):
4848
bf_df = scalar_types_df[["int64_col", "bool_col"]]
49-
sql = utils._apply_binary_op(bf_df, ops.eq_null_match_op, "int64_col", "bool_col")
49+
sql = utils._apply_nary_op(bf_df, ops.eq_null_match_op, "int64_col", "bool_col")
5050
snapshot.assert_match(sql, "out.sql")
5151

5252

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_to_json_string(json_types_df: bpd.DataFrame, snapshot):
102102

103103
def test_json_set(json_types_df: bpd.DataFrame, snapshot):
104104
bf_df = json_types_df[["json_col"]]
105-
sql = utils._apply_binary_op(
105+
sql = utils._apply_nary_op(
106106
bf_df, ops.JSONSet(json_path="$.a"), "json_col", ex.const(100)
107107
)
108108

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ def test_zfill(scalar_types_df: bpd.DataFrame, snapshot):
308308

309309
def test_add_string(scalar_types_df: bpd.DataFrame, snapshot):
310310
bf_df = scalar_types_df[["string_col"]]
311-
sql = utils._apply_binary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
311+
sql = utils._apply_nary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
312312

313313
snapshot.assert_match(sql, "out.sql")
314314

315315

316316
def test_strconcat(scalar_types_df: bpd.DataFrame, snapshot):
317317
bf_df = scalar_types_df[["string_col"]]
318-
sql = utils._apply_binary_op(bf_df, ops.strconcat_op, "string_col", ex.const("a"))
318+
sql = utils._apply_nary_op(bf_df, ops.strconcat_op, "string_col", ex.const("a"))
319319

320320
snapshot.assert_match(sql, "out.sql")

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,12 @@
1717
import pytest
1818

1919
from bigframes import operations as ops
20-
from bigframes.core import expression as ex
2120
import bigframes.pandas as bpd
2221
from bigframes.testing import utils
2322

2423
pytest.importorskip("pytest_snapshot")
2524

2625

27-
def _apply_nary_op(
28-
obj: bpd.DataFrame,
29-
op: ops.NaryOp,
30-
*args: typing.Union[str, ex.Expression],
31-
) -> str:
32-
"""Applies a nary op to the given DataFrame and return the SQL representing
33-
the resulting DataFrame."""
34-
array_value = obj._block.expr
35-
op_expr = op.as_expr(*args)
36-
result, col_ids = array_value.compute_values([op_expr])
37-
38-
# Rename columns for deterministic golden SQL results.
39-
assert len(col_ids) == 1
40-
result = result.rename_columns({col_ids[0]: "result_col"}).select_columns(
41-
["result_col"]
42-
)
43-
44-
sql = result.session._executor.to_sql(result, enable_cache=False)
45-
return sql
46-
47-
4826
def test_struct_field(nested_structs_types_df: bpd.DataFrame, snapshot):
4927
col_name = "people"
5028
bf_df = nested_structs_types_df[[col_name]]
@@ -63,6 +41,6 @@ def test_struct_field(nested_structs_types_df: bpd.DataFrame, snapshot):
6341
def test_struct_op(scalar_types_df: bpd.DataFrame, snapshot):
6442
bf_df = scalar_types_df[["bool_col", "int64_col", "float64_col", "string_col"]]
6543
op = ops.StructOp(column_names=tuple(bf_df.columns.tolist()))
66-
sql = _apply_nary_op(bf_df, op, *bf_df.columns.tolist())
44+
sql = utils._apply_nary_op(bf_df, op, *bf_df.columns.tolist())
6745

6846
snapshot.assert_match(sql, "out.sql")

0 commit comments

Comments
 (0)