设为首页 加入收藏

TOP

Scala   WordCount
2019-04-15 13:13:27 】 浏览:9
Tags:Scala   WordCount

1.最基本的WordCount

 var arr3 = Array("HIVE SPARK", "scala SPARK HBASE", "ZOOKEEPER","HIVE SPARK", "scala SPARK HBASE", "ZOOKEEPER")
    var arr4=arr3.flatMap(x => x.split(" "))
    var arr5=arr4.map(x=>(x,1))
    var arr6=arr5.groupBy(x=>(x._1))
    val arr7=arr6.map(x=>(x._1,x._2.length))
    print(arr7)

结果:

2.降序排序求top3

var arr1 = Array("HIVE SPARK", "scala SPARK HBASE", "ZOOKEEPER", "HIVE SPARK", "scala SPARK HBASE", "ZOOKEEPER SPARK HIVE HIVE", "ZOOKEEPER")
    var arr2=arr1.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).map(x=>(x._1,x._2.length)).toList.sortBy(-_._2).take(3)
    println(arr2.mkString)

结果:


编程开发网
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Spark之   Spark Streaming.. 下一篇Spark与深度学习框架——H2O、dee..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(214) }