gpt4 book ai didi

hadoop - mapreduce 作业的映射阶段的输出是否总是排序?

转载 作者:可可西里 更新时间:2023-11-01 14:18:37 25 4
gpt4 key购买 nike

我对从 Mapper 获得的输出有点困惑。

例如,当我使用以下输入文本运行一个简单的 wordcount 程序时:

hello world
Hadoop programming
mapreduce wordcount
lets see if this works
12345678
hello world
mapreduce wordcount

这是我得到的输出:

12345678    1
Hadoop 1
hello 1
hello 1
if 1
lets 1
mapreduce 1
mapreduce 1
programming 1
see 1
this 1
wordcount 1
wordcount 1
works 1
world 1
world 1

如您所见,mapper 的输出已经排序。我根本没有运行 Reducer。但是我在另一个项目中发现 mapper 的输出没有排序。所以我完全清楚这一点..

我的问题是:

  1. 映射器的输出总是排序的吗?
  2. sort 阶段是否已经集成到 mapper 阶段,以便 map 阶段的输出已经在中间数据中排序?
  3. 有没有一种方法可以从sort and shuffle 阶段收集数据,并在数据进入 Reducer 之前将其持久化? reducer 提供了一个键和一个可迭代列表。有没有办法,我可以保留这些数据?

最佳答案

Is the mapper's output always sorted?

没有。如果不使用 reducer ,则不会对其进行排序。如果使用 reducer,在将 mapper 的输出写入磁盘之前会有一个预排序过程。数据在 Reduce 阶段进行排序。这里发生的事情(只是一个猜测)是您没有指定 Reducer 类,在新的 API 中,该类被转换为使用 Identity Reducer(参见 this answer 和注释)。 Identity Reducer 只是输出它的输入。要验证这一点,请查看默认的 Reducer 计数器(应该有一些 reduce task ,减少输入记录和组,减少输出记录......)

Is the sort phase integrated into the mapper phase already, so that the output of map phase is already sorted in the intermediate data?

正如我在上一个问题中所解释的那样,如果您不使用缩减器,则映射器不会对数据进行排序。如果您确实使用 reducer,数据会从 map 阶段开始排序,然后在 reduce 阶段进行合并排序。

Is there a way to collect the data from sort and shuffle phase and persist it before it goes to Reducer. A reducer is presented with a key and a list of iterables. Is there a way, I could persist this data?

同样,洗牌和排序是 Reduce 阶段的一部分。 Identity Reducer 会做你想做的事。如果你想为每个 reducer 输出一个键值对,值是可迭代对象的串联,只需将可迭代对象存储在内存中(例如,在 StringBuffer 中),然后将这个串联输出为一个值。如果您希望 map 输出直接进入程序输出,而不经过 reduce 阶段,则在驱动程序类中将 reduce 任务的数量设置为零,如下所示:

job.setNumReduceTasks(0);

不过,这不会对您的输出进行排序。它将跳过映射器的预排序过程,并将输出直接写入HDFS。

关于hadoop - mapreduce 作业的映射阶段的输出是否总是排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24771006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com