2

I have list of person records in following format:

case class Person(fName:String, city:String) 

val l=List(Person("A","City1"),Person("B","City2"),Person("C","City1")) 

val rdd:RDD[Person]=sc.parallelize(l) 

val groupBy:RDD[(String, Iterable[Person])]=rdd.groupBy(_.city) 

I would like to save these group by records in different files (for example by city). Please can some one help me here.

I tried this but not able to create those files

groupBy.foreach(x=>{ 
x._2.toList.toDF().rdd.saveAsObjectFile(s"file:///tmp/files/${x._1}") 
}) 

Thanks Arun

ASe
  • 535
  • 5
  • 15
  • I have seen that solution, I don't think it is duplicate. My problem statement is different. Tried the one given solution, but did not see working. – ASe Sep 01 '17 at 15:40

0 Answers0