...

Cloud Computing - spark

Back to Course

Lesson Description


Lession - #778 SortByKey Function


sortByKey

In Spark, the sortByKey work keeps the control of components. It gets key-esteem matches (K, V>
as an information, sorts the components in rising or diving request and produces a dataset in a request.

Example of sortByKey function
In this model, we organize the components of dataset in rising and slipping request.
  • To open the Spark in Scala mode, follow the beneath order.

$ flash shell



  • Make a RDD utilizing the parallelized assortment.

scala> val information = sc.parallelize(Seq(("C",3>
,("A",1>
,("D",4>
,("B",2>
,("E",5>
>
>

  • Presently, we can peruse the created outcome by utilizing the accompanying order.

scala> data.collect



  • Apply sortByKey(>
    capacity to disregard copy components.

scala> val sortfunc = data.sortByKey(>

  • Presently, we can peruse the created outcome by utilizing the accompanying order.

scala> sortfunc.collect



Here, we got the ideal result. For dropping,
  • Apply sortByKey(>
    capacity and pass Boolean sort as boundary.

scala> val sortfunc = data.sortByKey(false>

    Presently, we can peruse the created outcome by utilizing the accompanying order.

scala> sortfunc.collect