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.

Added in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
colColumn or column name

target column to work on. A column that evaluates to a long, binary, or string.

Returns:
Column

hexadecimal representation of given value as string. Returns a column that evaluates to a 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|
+---+---+------+------+