Skip to content

daft.functions.try_deserialize#

try_deserialize #

try_deserialize(expr: Expression, format: Literal['json'], dtype: DataTypeLike) -> Expression

Deserializes a string using the specified format and data type, inserting nulls on failures.

Parameters:

Name Type Description Default
expr Expression

The expression to deserialize.

required
format Literal['json']

The serialization format.

required
dtype DataTypeLike

The target data type to deserialize into.

required

Returns:

Name Type Description
Expression Expression

A new expression with the deserialized value (or null).

Source code in daft/functions/str.py
28
29
30
31
32
33
34
35
36
37
38
39
40
def try_deserialize(expr: Expression, format: Literal["json"], dtype: DataTypeLike) -> Expression:
    """Deserializes a string using the specified format and data type, inserting nulls on failures.

    Args:
        expr: The expression to deserialize.
        format (Literal["json"]): The serialization format.
        dtype: The target data type to deserialize into.

    Returns:
        Expression: A new expression with the deserialized value (or null).
    """
    dtype = DataType._infer(dtype)
    return Expression._call_builtin_scalar_fn("try_deserialize", expr, format=format, dtype=dtype._dtype)