How to define Scala UDF in Spark

case class User(firstName:String, lastName: String, age:Integer)
val users = Seq(
User("Sachin","Tendulkar",43),
User("Rahul","Dravid",43),
User("Virat","Kohli",27),
User("MahendraSingh","Dhoni",34)
)
val userDF = sc.parallelize(users).toDF()
val evenNumber = udf{age:Integer => age%2 == 0}
val usersWithEvenNumberAge = userDF.filter(evenNumber(userDF("age")))
usersWithEvenNumberAge.show()
view raw sampleudf.scala hosted with ❤ by GitHub
Scala UDF Sample Notebook