Why filter throws error type mismatch

Why cant I apply filter on the RDD (Orderid ,(date,total )) and get only data for orderid =2 .
Is there any other method

scala> val Ojoin = Odata.join(Oitem)
Ojoin: org.apache.spark.rdd.RDD[(Int, (String, Float))] = MapPartitionsRDD[10] at join at :33

scala> Ojoin.take(5)
res4: Array[(Int, (String, Float))] = Array((41234,(2014-04-04 00:00:00.0,109.94)), (65722,(2014-05-23 00:00:00.0,119.98)), (65722,(2014-05-23 00:00:00.0,400.0)), (65722,(2014-05-23 00:00:00.0,399.98)), (65722,(2014-05-23 00:00:00.0,199.95)))

Ojoin.filter( k => { if (k._1 ==2 ) k } ) // shows invalid type error

Because filter it self consist If condition which is not required to specified for filter. It always return Boolean.
Ojoin.filter(_._1==2).sortByKey().collect().foreach(println)

1 Like