x.split(" "))   var arr5=arr4.map(x=>(x,1)..">

TOP

Scala   WordCount
2019-05-15 01:13:28 】 浏览:142
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)

结果:


Scala   WordCount https://www.cppentry.com/bencandy.php?fid=116&id=224174

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇        .. 下一篇        ..

kafka-
kafka   Partit
解决android studio
Kafka史上最详细原理
Error while fetchin
【Kafka】安装与快速
    &
flume读取日志数据写
Authentication plug
Flume 自定义source
flume   三大核
ICC副本>>>
愚公移山  
Hbase架构   Hb
5 hbase-shell + &
Hbase   MapRed
MetaException(messa
Exception in thread
HIVE metastore Dupl
-->