snowflake.snowpark.functions.to_binary

snowflake.snowpark.functions.to_binary(e: Union[Column, str], fmt: Optional[str] = None) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L6247-L6264)

Converts the input expression to a binary value. For NULL input, the output is NULL.

Example:

>>> df = session.create_dataframe(['00', '67', '0312'], schema=['a'])
>>> df.select(to_binary(col('a')).as_('ans')).collect()
[Row(ANS=bytearray(b'\x00')), Row(ANS=bytearray(b'g')), Row(ANS=bytearray(b'\x03\x12'))]

>>> df = session.create_dataframe(['aGVsbG8=', 'd29ybGQ=', 'IQ=='], schema=['a'])
>>> df.select(to_binary(col('a'), 'BASE64').as_('ans')).collect()
[Row(ANS=bytearray(b'hello')), Row(ANS=bytearray(b'world')), Row(ANS=bytearray(b'!'))]

>>> df.select(to_binary(col('a'), 'UTF-8').as_('ans')).collect()
[Row(ANS=bytearray(b'aGVsbG8=')), Row(ANS=bytearray(b'd29ybGQ=')), Row(ANS=bytearray(b'IQ=='))]
Copy
语言: 中文