pyspark.sql.functions.greatest#

pyspark.sql.functions.greatest(*cols)[source]#

Returns the greatest value of the list of column names, skipping null values. This function takes at least 2 parameters. It will return null if all parameters are null.

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
cols: :class:`~pyspark.sql.Column` or column name

columns to check for greatest value.

Returns
Column

greatest value.

Examples

>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([(1, 4, 3)], ['a', 'b', 'c'])
>>> df.select("*", sf.greatest(df.a, "b", df.c)).show()
+---+---+---+-----------------+
|  a|  b|  c|greatest(a, b, c)|
+---+---+---+-----------------+
|  1|  4|  3|                4|
+---+---+---+-----------------+