@@ -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 )
279316def test_engines_astype_timedelta (scalars_array_value : array_value .ArrayValue , engine ):
280317 arr = apply_op (
0 commit comments