pyspark.sql.functions.decode#

pyspark.sql.functions.decode(col, charset)[source]#

Computes the first argument into a string from a binary using the provided character set (one of β€˜US-ASCII’, β€˜ISO-8859-1’, β€˜UTF-8’, β€˜UTF-16BE’, β€˜UTF-16LE’, β€˜UTF-16’, β€˜UTF-32’).

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or column name

target column to work on.

charsetliteral string

charset to use to decode to.

Returns
Column

the column for computed results.

Examples

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([(b"abcd",)], ["a"])
>>> df.select("*", sf.decode("a", "UTF-8")).show()
+-------------+----------------+
|            a|decode(a, UTF-8)|
+-------------+----------------+
|[61 62 63 64]|            abcd|
+-------------+----------------+