Sorting on list, map, rdd has been so confusing



Can anyone recommend a good resource for explaining the sorting in Scala on List, Map, RDD…

I have been working on Sorting and so far I am very frustrated with what it is in the current Scala, so confusing, different to list, map and rdd, working here and not there…

Here is an example:
val orders = sc.textFile("/public/retail_db/orders")

68861,2014-06-13 00:00:00.0,3031,PENDING_PAYMENT
68862,2014-06-15 00:00:00.0,7326,PROCESSING
68863,2014-06-16 00:00:00.0,3361,CLOSED
68864,2014-06-18 00:00:00.0,9634,ON_HOLD

scala> val asc = ordersm.sortBy(_._1)


scala> val desc = ordersm.sortBy(_._1, false)

Now, let’s work on Status column as key, same method will fail

val orders1 =>(x.split(",")(3),x.split(",")(0)))

val orders1_w_count = orders1.countByKey

scala> orders1_w_count.take(10).foreach(println)

Now sorting

on the count asc
scala> val asc1 = orders1_w_count.sortBy(_.1)
:33: error: value sortBy is not a member of scala.collection.Map[String,Long]
** val asc1 = orders1_w_count.sortBy(

It seems orders1.countByKey transformed orders1 to a different type and caused the sortBy not available

What command should I use to sort the orders1.countByKey result?

Thank you very much.


Please use the commands as you are trying to sort the immutable ListMap.

import scala.collection.immutable.ListMap

image for your reference: