吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1832|回复: 3
收起左侧

[求助] mapreduce 单词统计怎么实现排序输出前5

[复制链接]
牵手丶若相惜 发表于 2019-10-8 19:56
文件:
REPORT ON THE WORK OF THE GOVERNMENT
Delivered at the Fifth Session of the 12th National People's Congress of the People's Republic of China on March 5, 2017
Li Keqiang
Premier of the State Council
Esteemed Deputies,
On behalf of the State Council, I will now report to you on the work of the government and ask for your deliberation and approval.
I also wish to have comments on my report from the members of the National Committee of the Chinese People's Political Consultative Conference (CPPCC).
Review of our work in 2016
In the past year, China's development has faced

需求:输出单词出现最多的前5
分隔符:空格

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

annybaby 发表于 2019-10-8 22:01
拆分,循环,统计,输出
吸水雨衣 发表于 2019-10-9 21:39
[Scala] 纯文本查看 复制代码
object Top3 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("Top3Scala").setMaster("local")
    val context = new SparkContext(conf)
    val linesRDD = context.textFile("E:\\testdata\\wordcount\\input\\top.txt")

    val pairs = linesRDD.map(line => (line.toInt, line))
    val sort = pairs.sortByKey(false)
    val result = sort.map(sort => sort._2)
    val strings = result.take(3)
    for(string <- strings) println("string = " + string)
  }
}
 楼主| 牵手丶若相惜 发表于 2019-10-10 15:28
吸水雨衣 发表于 2019-10-9 21:39
[mw_shl_code=scala,true]object Top3 {
  def main(args: Array[String]): Unit = {
    val conf = new ...

有没有Java的代码
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-30 10:17

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表