snowflake.snowpark.functions.try_hex_decode_binary

snowflake.snowpark.functions.try_hex_decode_binary(input_expr: Union[snowflake.snowpark.column.Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.43.0/src/snowflake/snowpark/_functions/scalar_functions.py#L4363-L4381)

Decodes a hex-encoded string to binary data. Returns None if the input is not a valid hex string.

Parameters:

input_expr (ColumnOrName) – A hex-encoded string to decode to binary data.

Returns:

The decoded binary data as bytearray, or None if input is invalid.

Return type:

Column

Examples::
>>> from snowflake.snowpark.functions import col
>>> df = session.create_dataframe([["41426162"], ["48656C6C6F"], ["576F726C64"]], schema=["hex_string"])
>>> df.select(try_hex_decode_binary(col("hex_string")).alias("decoded_binary")).collect()
[Row(DECODED_BINARY=bytearray(b'ABab')), Row(DECODED_BINARY=bytearray(b'Hello')), Row(DECODED_BINARY=bytearray(b'World'))]
Copy
Language: English