Skip to content

Commit 7744f56

Browse files
committed
uniform json golden sql tests
1 parent 8baa912 commit 7744f56

File tree

6 files changed

+85
-17
lines changed

6 files changed

+85
-17
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`rowindex` AS `bfcol_0`,
4+
`json_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`json_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
JSON_EXTRACT_ARRAY(`bfcol_1`, '$') AS `bfcol_4`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_0` AS `rowindex`,
14+
`bfcol_4` AS `json_col`
15+
FROM `bfcte_1`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`rowindex` AS `bfcol_0`,
4+
`json_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`json_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
JSON_EXTRACT_STRING_ARRAY(`bfcol_1`, '$') AS `bfcol_4`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_0` AS `rowindex`,
14+
`bfcol_4` AS `json_col`
15+
FROM `bfcte_1`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`rowindex` AS `bfcol_0`,
4+
`json_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`json_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
JSON_QUERY(`bfcol_1`, '$') AS `bfcol_4`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_0` AS `rowindex`,
14+
`bfcol_4` AS `json_col`
15+
FROM `bfcte_1`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`rowindex` AS `bfcol_0`,
4+
`json_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`json_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
JSON_QUERY_ARRAY(`bfcol_1`, '$') AS `bfcol_4`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_0` AS `rowindex`,
14+
`bfcol_4` AS `json_col`
15+
FROM `bfcte_1`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
WITH `bfcte_0` AS (
2+
SELECT
3+
`rowindex` AS `bfcol_0`,
4+
`json_col` AS `bfcol_1`
5+
FROM `bigframes-dev`.`sqlglot_test`.`json_types`
6+
), `bfcte_1` AS (
7+
SELECT
8+
*,
9+
JSON_VALUE(`bfcol_1`, '$') AS `bfcol_4`
10+
FROM `bfcte_0`
11+
)
12+
SELECT
13+
`bfcol_0` AS `rowindex`,
14+
`bfcol_4` AS `json_col`
15+
FROM `bfcte_1`

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,32 @@ def test_array_slice_with_start_and_stop(repeated_types_df: bpd.DataFrame, snaps
4747
# JSON Ops
4848
def test_json_extract(json_types_df: bpd.DataFrame, snapshot):
4949
result = bbq.json_extract(json_types_df["json_col"], "$")
50-
expected_sql = "JSON_EXTRACT(`bfcol_1`, '$') AS `bfcol_4`"
51-
assert expected_sql in result.to_frame().sql
5250
snapshot.assert_match(result.to_frame().sql, "out.sql")
5351

5452

55-
def test_json_extract_array(json_types_df: bpd.DataFrame):
53+
def test_json_extract_array(json_types_df: bpd.DataFrame, snapshot):
5654
result = bbq.json_extract_array(json_types_df["json_col"], "$")
57-
expected_sql = "JSON_EXTRACT_ARRAY(`bfcol_1`, '$') AS `bfcol_4`"
58-
assert expected_sql in result.to_frame().sql
55+
snapshot.assert_match(result.to_frame().sql, "out.sql")
5956

6057

61-
def test_json_extract_string_array(json_types_df: bpd.DataFrame):
58+
def test_json_extract_string_array(json_types_df: bpd.DataFrame, snapshot):
6259
result = bbq.json_extract_string_array(json_types_df["json_col"], "$")
63-
expected_sql = "JSON_EXTRACT_STRING_ARRAY(`bfcol_1`, '$') AS `bfcol_4`"
64-
assert expected_sql in result.to_frame().sql
60+
snapshot.assert_match(result.to_frame().sql, "out.sql")
6561

6662

67-
def test_json_query(json_types_df: bpd.DataFrame):
63+
def test_json_query(json_types_df: bpd.DataFrame, snapshot):
6864
result = bbq.json_query(json_types_df["json_col"], "$")
69-
expected_sql = "JSON_QUERY(`bfcol_1`, '$') AS `bfcol_4`"
70-
assert expected_sql in result.to_frame().sql
65+
snapshot.assert_match(result.to_frame().sql, "out.sql")
7166

7267

73-
def test_json_query_array(json_types_df: bpd.DataFrame):
68+
def test_json_query_array(json_types_df: bpd.DataFrame, snapshot):
7469
result = bbq.json_query_array(json_types_df["json_col"], "$")
75-
expected_sql = "JSON_QUERY_ARRAY(`bfcol_1`, '$') AS `bfcol_4`"
76-
assert expected_sql in result.to_frame().sql
70+
snapshot.assert_match(result.to_frame().sql, "out.sql")
7771

7872

79-
def test_json_value(json_types_df: bpd.DataFrame):
73+
def test_json_value(json_types_df: bpd.DataFrame, snapshot):
8074
result = bbq.json_value(json_types_df["json_col"], "$")
81-
expected_sql = "JSON_VALUE(`bfcol_1`, '$') AS `bfcol_4`"
82-
assert expected_sql in result.to_frame().sql
75+
snapshot.assert_match(result.to_frame().sql, "out.sql")
8376

8477

8578
def test_parse_json(scalar_types_df: bpd.DataFrame, snapshot):

0 commit comments

Comments
 (0)