nvl
Returns col2 if col1 is null, or col1 otherwise.
For the corresponding Databricks SQL function, see nvl function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.nvl(col1=<col1>, col2=<col2>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The first column to check. |
|
| The value to return if col1 is null. |
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(None, 8,), (1, 9,)], ["a", "b"])
df.select('*', dbf.nvl(df.a, df.b)).show()
Output
+----+---+--------+
| a| b|nvl(a, b)|
+----+---+--------+
|NULL| 8| 8|
| 1| 9| 1|
+----+---+--------+