-1

I have this code :

def contentSizeStats(rdd: RDD[ApacheAccessLog]) = {
  val contentSizes = rdd.map(x=>x.contentSize).cache()
  val count = contentSizes.count()
   if (count == 0) { null }
   (count, contentSizes.reduce(_+_), contentSizes.min(), contentSizes.max())
}

The return value of this function is (Long, String, String, String), I am trying to save the result of this function to a text file using saveAsTextFile and I cant since the result is not an RDD,any idea how to implement this ?

Achillies57
  • 51
  • 1
  • 5
  • 1
    Possible duplicate of [How to write to a file in Scala?](http://stackoverflow.com/questions/4604237/how-to-write-to-a-file-in-scala) – zero323 Nov 07 '15 at 17:46

1 Answers1

1

You can convert the return value to an RDD and then call saveAsTextFile on it.

val outputRdd = sc.parallelize(outputTuple.productIterator.toArray)
outputRdd.saveAsTextFile(outputDirectory)
Prayag
  • 111
  • 1
  • 5
  • Thanks for the reply,but the output of the function is not an array, so the above wont work.(I even tried it, says type mismatch) – Achillies57 Nov 07 '15 at 20:57
  • How about convert the tuple to an array first? You can do `outputTuple.productIterator.toArray` – Prayag Nov 07 '15 at 21:05