pyspark.sql.functions.hex#

pyspark.sql.functions.hex(col)[source]#

Computes hex value of the given column, which could be pyspark.sql.types.StringType, pyspark.sql.types.BinaryType, pyspark.sql.types.IntegerType or pyspark.sql.types.LongType.

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.

Returns
Column

hexadecimal representation of given value as string.

Examples

>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([('ABC', 3)], ['a', 'b'])
>>> df.select('*', sf.hex('a'), sf.hex(df.b)).show()
+---+---+------+------+
|  a|  b|hex(a)|hex(b)|
+---+---+------+------+
|ABC|  3|414243|     3|
+---+---+------+------+