nullif
Retourne null si col1 est égal à col2, ou col1 sinon.
Pour la fonction Databricks SQL correspondante, consultez la fonctionnullif.
Syntaxe
Python
from pyspark.sql import functions as dbf
dbf.nullif(col1=<col1>, col2=<col2>)
parameter
parameter | Type | Description |
|---|---|---|
|
| La première colonne à vérifier. |
|
| La colonne à comparer avec col1. |
Exemples
Python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(None, None,), (1, 9,)], ["a", "b"])
df.select('*', dbf.nullif(df.a, df.b)).show()
Output
+----+----+------------+
| a| b|nullif(a, b)|
+----+----+------------+
|NULL|NULL| NULL|
| 1| 9| 1|
+----+----+------------+