snowflake.snowpark.functions.try_base64_decode_binary¶
- snowflake.snowpark.functions.try_base64_decode_binary(input_expr: Union[snowflake.snowpark.column.Column, str], alphabet: Union[snowflake.snowpark.column.Column, str] = None) Column[source]¶
Decodes a base64-encoded string to binary data. Returns None if the input is not valid base64.
- Parameters:
input_expr (ColumnOrName) – The base64-encoded string to decode.
alphabet (ColumnOrName, optional) – The base64 alphabet to use for decoding. If not specified, uses the standard base64 alphabet.
- Returns:
A column containing the decoded binary data, or None if the input is invalid.
- Return type:
- Examples::
>>> from snowflake.snowpark.functions import base64_encode >>> df = session.create_dataframe(["HELP", "TEST"], schema=["input"]) >>> df.select(try_base64_decode_binary(base64_encode(df["input"])).alias("result")).collect() [Row(RESULT=bytearray(b'HELP')), Row(RESULT=bytearray(b'TEST'))]
>>> df2 = session.create_dataframe(["SEVMUA==", "VEVTVA=="], schema=["encoded"]) >>> df2.select(try_base64_decode_binary(df2["encoded"]).alias("result")).collect() [Row(RESULT=bytearray(b'HELP')), Row(RESULT=bytearray(b'TEST'))]
>>> df3 = session.create_dataframe(["invalid_base64!"], schema=["bad_input"]) >>> df3.select(try_base64_decode_binary(df3["bad_input"]).alias("result")).collect() [Row(RESULT=None)]
>>> df4 = session.create_dataframe(["SEVMUA=="], schema=["encoded"]) >>> df4.select(try_base64_decode_binary(df4["encoded"], lit("$")).alias("result")).collect() [Row(RESULT=bytearray(b'HELP'))]