I have a dataframe (mydf) as follows:
+---+---+---+---+
| F1| F2| F3| F4|
+---+---+---+---+
| t| y4| 5|1.0|
| x| y| 1|0.5|
| x| y| 1|0.5|
| x| z| 2|1.0|
| x| b| 5|1.0|
| t| y2| 6|1.0|
| t| y3| 3|1.0|
| x| a| 4|1.0|
+---+---+---+---+
I want to do a conditional aggregation inside "withColumn" as follows:
mydf.withColumn("myVar", if($"F3" > 3) sum($"F4") else 0.0)
that is for every row having $F3 <= 0 , myVar should have a value of 0.0 and others sum of $"F4".
How to achieve it in Spark Scala?