Hi All,
While implementing sort By Key operation i am getting some error.
It is my sample data.
scala> productsMap.take(4).foreach(println)
(2,(Q64,59.98))
(2,(Armour,129.99))
(2,(Armour,89.99))
(2,(Armour,89.99))
(Product_department_id , (products_name , price ) )
val productsMapGroup = productsMap.groupByKey().map(x => ( x._2.toList.sortBy( k => k.split(",")(1)) ) )
:31: error: value split is not a member of (String, Float)
** val productsMapGroup = productsMap.groupByKey().map(x => ( x._2.toList.sortBy( k => k.split(",")(1)) ) )**
Up to my understanding , (x => ( x._2.toList.sortBy( k => k.split(",")(1)) ) ) the variable x is ((products_name , price ) ) since we used x._2 tuple notation but we have turned the tuple into list by type casting it .
The error show it is still a list so i tried this by still considering it a list and used below command .
val productsMapGroup = productsMap.groupByKey().map(x => ( x._1 , x._2.toList.sortBy( k => k._2) ) )
productsMapGroup: org.apache.spark.rdd.RDD[(String, List[(String, Float)])] = MapPartitionsRDD[10] at map at :31
The Command ran successfully and the result is correct .
Kindly let me know the problem in it.