Spark two-time sort

Source: Internet
Author: User

Compared to Java, Scala's code is much leaner:

import org.apache.spark._ import sparkcontext._ object secondarysort {   def main (args: array[string])  {    val sparkconf = new  sparkconf (). Setappname (" Secondary Sort ")     sparkconf.set (" Mapreduce.framework.name ", " yarn ");         sparkconf.set (" Spark.rdd.compress ", " true ");         sparkconf.set (" Spark.serializer "," Org.apache.spark.serializer.KryoSerializer ");         sparkconf.set ("spark.storage.memoryFraction",  "0.5");         sparkconf.set ("Spark.akka.frameSize",  ");         Sparkconf.set ("Spark.default.parallelism",  "1");      val sc = new  sparkcontext (sparkconf)     val file = sc.textfile ("Hdfs://namenode:9000/test/secsortdata")     val  Rdd = file.map (Line => line.split ("\ T")).       map (x  =>  (x (0), X (1)). Groupbykey ().       sortbykey (True). Map (x = >  (X._1,x._2.tolist.sortwith (_>_)))     val rdd2 = rdd.flatmap{       x =>      val len = x . _2.length      val array = new array[(String,String)] (len)       for (I <- 0 until len)  {         array (i)  =  (x._1,x._2 (i))       }       array      }    sc.stop ()   }}

is not very simple, compared to the mapreduce hundreds of lines of code is really convenient and fast

Spark two-time sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.