Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 3b7ce8e

Browse files
committed
feat: guard polar engine
1 parent 4134750 commit 3b7ce8e

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

bigframes/core/compile/polars/compiler.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,13 @@ def _(self, op: ops.ScalarOp, input: pl.Expr) -> pl.Expr:
429429
@compile_op.register(json_ops.JSONDecode)
430430
def _(self, op: ops.ScalarOp, input: pl.Expr) -> pl.Expr:
431431
assert isinstance(op, json_ops.JSONDecode)
432-
return input.str.json_decode(_DTYPE_MAPPING[op.to_type])
432+
if op.safe:
433+
# Polars does not support safe JSON decoding (returning null on failure).
434+
# Fallback to BigQuery execution.
435+
raise NotImplementedError(
436+
"Safe JSON decoding is not supported in Polars executor."
437+
)
438+
return input.str.json_decode(_bigframes_dtype_to_polars_dtype(op.to_type))
433439

434440
@compile_op.register(arr_ops.ToArrayOp)
435441
def _(self, op: ops.ToArrayOp, *inputs: pl.Expr) -> pl.Expr:

bigframes/core/compile/polars/lowering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _lower_cast(cast_op: ops.AsTypeOp, arg: expression.Expression):
391391
return arg
392392

393393
if arg.output_type == dtypes.JSON_DTYPE:
394-
return json_ops.JSONDecode(cast_op.to_type).as_expr(arg)
394+
return json_ops.JSONDecode(cast_op.to_type, safe=cast_op.safe).as_expr(arg)
395395
if (
396396
arg.output_type == dtypes.STRING_DTYPE
397397
and cast_op.to_type == dtypes.DATETIME_DTYPE

bigframes/operations/json_ops.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def output_type(self, *input_types):
220220
class JSONDecode(base_ops.UnaryOp):
221221
name: typing.ClassVar[str] = "json_decode"
222222
to_type: dtypes.Dtype
223+
safe: bool = False
223224

224225
def output_type(self, *input_types):
225226
input_type = input_types[0]

bigframes/session/polars_executor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
numeric_ops,
3535
string_ops,
3636
)
37+
import bigframes.operations.json_ops as json_ops
3738
from bigframes.session import executor, semi_executor
3839

3940
if TYPE_CHECKING:
@@ -94,6 +95,7 @@
9495
string_ops.EndsWithOp,
9596
string_ops.StrContainsOp,
9697
string_ops.StrContainsRegexOp,
98+
json_ops.JSONDecode,
9799
)
98100
_COMPATIBLE_AGG_OPS = (
99101
agg_ops.SizeOp,

0 commit comments

Comments
 (0)