sorting - 如何对map reduce hadoop中的数据进行排序?

标签 sorting hadoop mapreduce

我正在使用一个包含 4 个 MapReduce 步骤的程序。我第一步的输出是:

id      value
 1        20
 2         3
 3         9
 4        36

我有大约 1,000,000 个 ID,在第二步中我必须对值进行排序。这一步的输出:

 id      value
 4        36
 1        20
 3         9
 2         3

如何在 map reduce 中对数据进行排序?我需要使用 terasort 吗?如果是,我如何在程序的第二步使用 terasort? 谢谢。

最佳答案

如果你想根据value's排序,让它成为key in map函数。即

id      value
1        20
2         3
3         9
4        36
5         3

map 函数中的(值)(键)

output will be 

key      value
3         5
3         2
9         3
20        1
36        4

map<value, id> output key/value  
reduce <value, id>

如果您希望 id 位于第一列,这将起作用。

context.write(value, key);

请注意,id 不会被排序

关于sorting - 如何对map reduce hadoop中的数据进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16402383/

相关文章:

.net - 在 DataGridView 中排序时等待光标

java - Spring有序的bean列表

algorithm - 排序值,但前提是它们比当前顺序多 X

hadoop - 在hadoop中,如何分别验证每个从节点上运行的map任务数?

javascript - mixitup 在页面加载后初始启动时计算可见项目

hadoop - 如何在Java中使用MapReduce找出hadoop中的双字计数

mysql - 从 HDFS 读取到 Spark

hadoop - 过滤命令在 Pig 中返回 0 条记录

java - mapreduce 作业中的 API 调用

linux - YarnApplicationState : ACCEPTED: waiting for AM container to be allocated, 启动并注册