Skip to content

Commit 821689d

Browse files
committed
tests: add engine tests for casting to json
1 parent b0ff718 commit 821689d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/system/small/engines/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ def scalars_array_value(
7373
return ArrayValue.from_managed(managed_data_source, fake_session)
7474

7575

76+
@pytest.fixture(scope="module")
77+
def nested_array_value(
78+
nested_data_source: local_data.ManagedArrowTable, fake_session: bigframes.Session
79+
):
80+
return ArrayValue.from_managed(nested_data_source, fake_session)
81+
82+
7683
@pytest.fixture(scope="module")
7784
def zero_row_source() -> local_data.ManagedArrowTable:
7885
return local_data.ManagedArrowTable.from_pandas(pd.DataFrame({"a": [], "b": []}))

tests/system/small/engines/test_generic_ops.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,43 @@ def test_engines_astype_from_json(scalars_array_value: array_value.ArrayValue, e
275275
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
276276

277277

278+
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
279+
def test_engines_astype_to_json(scalars_array_value: array_value.ArrayValue, engine):
280+
exprs = [
281+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
282+
expression.deref("int64_col")
283+
),
284+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
285+
# Use a const since float to json has precision issues
286+
expression.const(5.2, bigframes.dtypes.FLOAT_DTYPE)
287+
),
288+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
289+
expression.deref("bool_col")
290+
),
291+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
292+
# Use a const since "str_col" has special chars.
293+
expression.const('"hello world"', bigframes.dtypes.STRING_DTYPE)
294+
),
295+
]
296+
arr, _ = scalars_array_value.compute_values(exprs)
297+
298+
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
299+
300+
301+
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
302+
def test_engines_astype_struct_to_json(
303+
nested_array_value: array_value.ArrayValue, engine
304+
):
305+
exprs = [
306+
ops.AsTypeOp(to_type=bigframes.dtypes.JSON_DTYPE).as_expr(
307+
expression.deref("label")
308+
),
309+
]
310+
arr, _ = nested_array_value.compute_values(exprs)
311+
312+
assert_equivalence_execution(arr.node, REFERENCE_ENGINE, engine)
313+
314+
278315
@pytest.mark.parametrize("engine", ["polars", "bq"], indirect=True)
279316
def test_engines_astype_timedelta(scalars_array_value: array_value.ArrayValue, engine):
280317
arr = apply_op(

0 commit comments

Comments
 (0)