I have a specific requirement wherein, i need to check for empty DataFrame. If empty then populate a default value. Here is what i tried but not getting what i want.
def checkNotEmpty(df: org.apache.spark.sql.DataFrame, col: String):org.apache.spark.sql.DataFrame =
{
if (!df.rdd.isEmpty()) df
else
df.na.fill(0, Seq(col))
}
val age = checkNotEmpty(w_feature_md.filter("age='22'").select("age_index"),"age_index")
The idea is to get the df if it is not empty. If it is empty then fill in a default value of ZERO. This doesn't seem to work. The following is what i am getting.
scala> age.show
+---------+
|age_index|
+---------+
+---------+
Please help..