Q: Sorting in Spark There exist some similar questions like this and this but they couldn't provide me sufficient help.
Following is a piece of my code. 
val output = abc.collect()
output.foreach(tup => println(tup._1 + "  " + math.ceil(tup._2 * 1000)/1000))

Following is a piece of the output.
 5         0.835
 1         0.901
 110       0.797
 7         0.821
 11        0.899
 0         0.871
 32        0.313
 78        0.273
 35698     0.333
 119       0.273

I want to have the output in sorted form.  I tried takeOrdered(n) but the output it gives is not what I need. It is sorted but perhaps as string, not numbers. It is something like
 0          0.871
 1          0.901
 10         1.072
 11         0.899
 110        0.797
 111        0.288
 12         0.288
 123        0.273
 14         0.554
 153        0.228

Any Help please?

A: There is some issue in using takeOrdered(n) with collect().
I tried val output = abc.takeOrdered(10000) and it perfectly worked.

A: Instead of first generating the output from the RDD and then applying sort, you could first sort your RDD and then create the output
val abc=sc.parallelize(Array(("5",0.835),("1",0.901),("110",0.797)))
abc.map{case (k,v)=>(k.toInt,v)}.takeOrdered(3).foreach(println(_))
//(1,0.901)
//(5,0.835)
//(110,0.797)

