Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Converts the input col to a binary value based on the supplied format. The format can be a case-insensitive string literal of "hex", "utf-8", "utf8", or "base64". By default, the binary format for conversion is "hex" if format is omitted. The function returns NULL if at least one of the input parameters is NULL.
For the corresponding Databricks SQL function, see to_binary function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.to_binary(col=<col>, format=<format>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
Input column or strings. |
format |
pyspark.sql.Column or str, optional |
format to use to convert binary values. |
Examples
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([("abc",)], ["e"])
df.select(dbf.try_to_binary(df.e, dbf.lit("utf-8")).alias('r')).collect()
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([("414243",)], ["e"])
df.select(dbf.try_to_binary(df.e).alias('r')).collect()