package com.bjsxt.spark
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
object map {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("test").setMaster("local")
val sc=new SparkContext(conf)
val lines=sc.textFile("./words");
val words =lines.flatMap(line=>{
line.split(" ")
})
val pairWords=words.map(word=>{
new Tuple2(word,1)
})
println("pairwords partitions ="+pairWords.partitions.length)
val reduceResult=pairWords.reduceByKey((v1,v2)=>{v1+v2},3)
println("pairwords partitions ="+reduceResult.partitions.length)
val result =reduceResult.sortBy(tuple=>{tuple._2},false)
result.foreach(tuple=>{
println(tuple)
})
sc.stop()
}
}