I have a DataFrame as below.
Value1 Value2 Value3
30000 40000 50000
null 20000 10000
Also, I have a UDF created as
val testUDF=udf((a: Double, b: Double, c: Double) => {
if(a==null && b!=null && c!=null)
b+c
else
a+b+c
})
I have a code as below.
input.withColumn("checkNull", testUDF(col("value1"),col("value2"),col("value3"))).show
Resulting dataframe is as
Value1 Value2 Value3 checkNull
30000 40000 50000 120000
null 20000 10000 null
Here, instead of displaying 3000 for second row for the column "checkNUll", it displayed, null. Any thing I am doing wrong in my code? I dont want to replace it with 0. Because, if I want to do multiplication instead of addition above, it will fail.