小练习——过滤掉出现次数最多的数据
生活随笔
收集整理的這篇文章主要介紹了
小练习——过滤掉出现次数最多的数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數據源:
hello george hello george hello george hello george hello george hello george George love George love George love george kangkang kangkang kangkang代碼:
package suanziimport org.apache.spark.{SparkConf, SparkContext}object FilterMost {def main(args: Array[String]): Unit = {val conf = new SparkConf().setMaster("local").setAppName("FilterMost")val sc = new SparkContext(conf)sc.setLogLevel("error")val rdd = sc.textFile("./data/words.txt")val result = rdd.flatMap(x => {x.split(" ")}).map((_, 1)).reduceByKey(_ + _).map(x => {(x._2, x._1)}).sortByKey(false).first()._2rdd.filter({!_.contains(result)}).foreach(println)sc.stop()} }結果展示:
George love George love George love kangkang kangkang?
總結
以上是生活随笔為你收集整理的小练习——过滤掉出现次数最多的数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设置分区的三种方法coalesce、re
- 下一篇: 简单的combineByKey算子【看完