在某些条件下,我们希望映射器完成所有工作并输出到 HDFS,我们不希望将数据传输到 reducer (将使用额外的带宽,如果有错误请纠正我)。
一个伪代码是:
def mapper(k,v_list):
for v in v_list:
if criteria:
write to HDFS
else:
emit
我发现这很难,因为我们唯一可以玩的就是 OutputCollector。 我想到的一件事是扩展 OutputCollector,覆盖 OutputCollector.collect 并执行这些操作。 有没有更好的方法?
最佳答案
您可以使用 JobConf.setNumReduceTasks(0) 将 reduce 任务的数量设置为 0。这将使映射器的结果直接进入 HDFS。
来自 Map-Reduce 手册:http://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html
Reducer NONE
It is legal to set the number of reduce-tasks to zero if no reduction is desired.
In this case the outputs of the map-tasks go directly to the FileSystem,
into the output path set by setOutputPath(Path). The framework does not sort
the map-outputs before writing them out to the FileSystem.
关于hadoop - 如何直接从mapper输出到HDFS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10289797/