This is a snippet of code in Spark/Scala:
rdd.sortBy(_._2)
What does _._2
mean here?
This is a snippet of code in Spark/Scala:
rdd.sortBy(_._2)
What does _._2
mean here?
In Scala _2
is shorthand for accessing second tuple element.
val myTuple = ("first", "second")
myTuple._1 // "first"
myTuple._2 // "second"
In your case all tuples in rdd
will be sorted by second element.
For example:
val tuples = Vector(("first", "b"),("second", "c"),("third", "a"))
tuples.sortBy(_._2) //Vector((third,a), (first,b), (second,c))