Skip to content

Commit cc85630

Browse files
committed
scalar tests use array_value rather than open APIs
1 parent dbccc47 commit cc85630

File tree

5 files changed

+40
-35
lines changed

5 files changed

+40
-35
lines changed

tests/unit/core/compile/sqlglot/expressions/snapshots/test_binary_compiler/test_add_numeric/out.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ WITH `bfcte_0` AS (
66
), `bfcte_1` AS (
77
SELECT
88
*,
9-
`bfcol_1` AS `bfcol_4`,
10-
`bfcol_0` + `bfcol_0` AS `bfcol_5`
9+
`bfcol_0` + `bfcol_0` AS `bfcol_4`
1110
FROM `bfcte_0`
1211
)
1312
SELECT
14-
`bfcol_4` AS `rowindex`,
15-
`bfcol_5` AS `int64_col`
13+
`bfcol_1` AS `bfuid_col_1`,
14+
`bfcol_0` AS `int64_col`,
15+
`bfcol_4` AS `bfuid_col_2`
1616
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_binary_compiler/test_add_numeric_w_scalar/out.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ WITH `bfcte_0` AS (
66
), `bfcte_1` AS (
77
SELECT
88
*,
9-
`bfcol_1` AS `bfcol_4`,
10-
`bfcol_0` + 1 AS `bfcol_5`
9+
`bfcol_0` + 1 AS `bfcol_4`
1110
FROM `bfcte_0`
1211
)
1312
SELECT
14-
`bfcol_4` AS `rowindex`,
15-
`bfcol_5` AS `int64_col`
13+
`bfcol_1` AS `bfuid_col_1`,
14+
`bfcol_0` AS `int64_col`,
15+
`bfcol_4` AS `bfuid_col_3`
1616
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_binary_compiler/test_add_string/out.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ WITH `bfcte_0` AS (
66
), `bfcte_1` AS (
77
SELECT
88
*,
9-
`bfcol_0` AS `bfcol_4`,
10-
CONCAT(`bfcol_1`, 'a') AS `bfcol_5`
9+
CONCAT(`bfcol_1`, 'a') AS `bfcol_4`
1110
FROM `bfcte_0`
1211
)
1312
SELECT
14-
`bfcol_4` AS `rowindex`,
15-
`bfcol_5` AS `string_col`
13+
`bfcol_0` AS `bfuid_col_1`,
14+
`bfcol_1` AS `string_col`,
15+
`bfcol_4` AS `bfuid_col_4`
1616
FROM `bfcte_1`

tests/unit/core/compile/sqlglot/expressions/snapshots/test_binary_compiler/test_json_set/out.sql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ WITH `bfcte_0` AS (
88
*,
99
JSON_SET(`bfcol_1`, '$.a', 100) AS `bfcol_4`
1010
FROM `bfcte_0`
11-
), `bfcte_2` AS (
12-
SELECT
13-
*,
14-
JSON_SET(`bfcol_4`, '$.b', 'hi') AS `bfcol_7`
15-
FROM `bfcte_1`
1611
)
1712
SELECT
18-
`bfcol_0` AS `rowindex`,
19-
`bfcol_7` AS `json_col`
20-
FROM `bfcte_2`
13+
`bfcol_0` AS `bfuid_col_5`,
14+
`bfcol_1` AS `json_col`,
15+
`bfcol_4` AS `bfuid_col_6`
16+
FROM `bfcte_1`

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,45 @@
1414

1515
import pytest
1616

17-
import bigframes.bigquery as bbq
17+
from bigframes import operations as ops
18+
import bigframes.core.expression as ex
1819
import bigframes.pandas as bpd
1920

2021
pytest.importorskip("pytest_snapshot")
2122

2223

23-
def test_add_numeric(scalar_types_df: bpd.DataFrame, snapshot):
24-
bf_df = scalar_types_df[["int64_col"]]
24+
def _apply_binary_op(
25+
obj: bpd.DataFrame | bpd.Series,
26+
op: ops.BinaryOp,
27+
l_arg: str | ex.Expression,
28+
r_arg: str | ex.Expression,
29+
) -> str:
30+
array_value = obj._block.expr
31+
op_expr = op.as_expr(l_arg, r_arg)
32+
result, _ = array_value.compute_values([op_expr])
33+
sql = result.session._executor.to_sql(result, enable_cache=False)
34+
return sql
2535

26-
bf_df["int64_col"] = bf_df["int64_col"] + bf_df["int64_col"]
2736

28-
snapshot.assert_match(bf_df.sql, "out.sql")
37+
def test_add_numeric(scalar_types_df: bpd.DataFrame, snapshot):
38+
bf_df = scalar_types_df[["int64_col"]]
39+
sql = _apply_binary_op(bf_df, ops.add_op, "int64_col", "int64_col")
40+
snapshot.assert_match(sql, "out.sql")
2941

3042

3143
def test_add_numeric_w_scalar(scalar_types_df: bpd.DataFrame, snapshot):
3244
bf_df = scalar_types_df[["int64_col"]]
33-
34-
bf_df["int64_col"] = bf_df["int64_col"] + 1
35-
36-
snapshot.assert_match(bf_df.sql, "out.sql")
45+
sql = _apply_binary_op(bf_df, ops.add_op, "int64_col", ex.const(1))
46+
snapshot.assert_match(sql, "out.sql")
3747

3848

3949
def test_add_string(scalar_types_df: bpd.DataFrame, snapshot):
4050
bf_df = scalar_types_df[["string_col"]]
41-
42-
bf_df["string_col"] = bf_df["string_col"] + "a"
43-
44-
snapshot.assert_match(bf_df.sql, "out.sql")
51+
sql = _apply_binary_op(bf_df, ops.add_op, "string_col", ex.const("a"))
52+
snapshot.assert_match(sql, "out.sql")
4553

4654

4755
def test_json_set(json_types_df: bpd.DataFrame, snapshot):
48-
result = bbq.json_set(json_types_df["json_col"], [("$.a", 100), ("$.b", "hi")])
49-
snapshot.assert_match(result.to_frame().sql, "out.sql")
56+
bf_df = json_types_df[["json_col"]]
57+
sql = _apply_binary_op(bf_df, ops.JSONSet(json_path="$.a"), "json_col", ex.const(100))
58+
snapshot.assert_match(sql, "out.sql")

0 commit comments

Comments
 (0)