标签:conf array textfile string nes .text object local split
object ScalaApp { def main(args: Array[String]): Unit = { var conf = new SparkConf() conf.setMaster("local") var sc = new SparkContext(conf) val lines: RDD[String] = sc.textFile("./words.txt") lines.flatMap(line=>line.split(" ")).map(word=>(word,1)).reduceByKey((v1,v2)=>v1+v2).foreach(println) // 简洁版 // lines.flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_).foreach(println) } }
标签:conf array textfile string nes .text object local split
原文地址:https://www.cnblogs.com/yehuabin/p/10294756.html