import org.apache.spark.{SparkConf, SparkContext} object Stone { def main(args: Array[String]): Unit = { val conf = new SparkConf().setAppName("stone").setMaster("local") val sc = new SparkContext(conf) sc.setLogLevel("ERROR") val file = sc.textFile("data/person.txt") val value = file.flatMap(_.split(" ")).map(x => new Tuple2(x, 1)).reduceByKey((x, y) => { x + y }) print("-------------------------") value.foreach (x =>println(x)) print("----------反转---------------") value.map(x => { (x._2 , 1) }).reduceByKey(_+_).foreach(println) } }
hell world
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)