In Scala Spark
val df = sc.parallelize(0 to 3).toDF("x")
df.registerTempTable("df")
sqlContext.sql("select * from df").show
+---+
| x|
+---+
| 0|
| 1|
| 2|
| 3|
+---+
and would like to average non zero values only. Tried this (does not work),
sqlContext.sql("select avg(nullif(x,0)) from df").show
What is a simple and efficient way to average non zero values ?