当前位置:首页 » Apache技术知识

Spark版wordcount,并根据词频进行排序

2017-10-10 10:41 本站整理 浏览(1)

import org.apache.spark.{SparkConf, SparkContext}
/**
* Created by loushsh on 2017/10/9.
*/
object WordCount {
def main(args:Array[String]): Unit ={
val conf=new SparkConf()
val sc=new SparkContext(conf)
val line= sc.textFile(args(0))
val count=line.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).sortBy(_._2,false).repartition(1).saveAsTextFile(args(1))
}
}