hadoop - outputcollector如何工作?

标签 hadoop mapreduce reduce partitioner

我正在尝试分析默认的map reduce作业,该作业没有定义mapper或reducer。
即使用IdentityMapper和IdentityReducer的一种
为了使自己清楚,我只是写了我的身份简化程序

public static class MyIdentityReducer extends MapReduceBase implements Reducer<Text,Text,Text,Text> {
        @Override
        public void reduce(Text key, Iterator<Text> values,
                OutputCollector<Text, Text> output, Reporter reporter)
                throws IOException {
            while(values.hasNext()) {
                Text value = values.next();
                output.collect(key, value);
            }
        }   
    }

我的输入文件是:
$ hadoop fs -cat NameAddress.txt
Dravid Banglore
Sachin Mumbai
Dhoni Ranchi
Dravid Jaipur
Dhoni Chennai
Sehwag Delhi
Gambhir Delhi
Gambhir Calcutta

I was expecting
Dravid Jaipur
Dhoni Chennai
Gambhir Calcutta
Sachin Mumbai
Sehwag Delhi

I got
$ hadoop fs -cat NameAddress/part-00000
Dhoni   Ranchi
Dhoni   Chennai
Dravid  Banglore
Dravid  Jaipur
Gambhir Delhi
Gambhir Calcutta
Sachin  Mumbai
Sehwag  Delhi

我认为,由于聚合是由程序员在化简器的while循环中完成的,然后再写入到outputcollector中。我的印象是,传递给outputcollector的reducer的键始终是唯一的&因为在这里如果我不进行聚合,则最后一个键的值将覆盖先前的值。显然不是这样。
有人可以给我更好的outputcollector现场知识,它如何工作以及如何处理所有键。我在hadoop src代码中看到了outputcollector的许多实现。
我可以编写自己的outputcollector来完成我的期望吗?

最佳答案

键对于化简器是唯一的,并且对化简器的每个调用都具有唯一的键值,并且该键值可迭代与该键关联的所有值。您正在做的是遍历传入的所有值并写出每个值。

因此,在您的情况下, call 数量可能少于数据数量。您仍然最终将所有值都写了出来。

关于hadoop - outputcollector如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12763478/

相关文章:

java - 使用凭据缓存的 Kerberos 身份验证通过 Eclipse 工作,但不能通过命令行工作

python - 通过 Thrift 在 HBase 中的 mutateRow() 需要未记录的第四个参数

hadoop - MapReduce 示例

memory - 在作业运行期间更改内存资源

arrays - 为什么我不能调用reduce(到:) on an array literal in Xcode 9. 2?

scala - Spark : difference of semantics between reduce and reduceByKey

maven - 使用 Maven 错误构建 Hadoop

amazon-web-services - 如何在EMR中的特定实例组上运行脚本

hadoop - yarn JobHistory 错误 : Failed redirect for container_1400260444475_3309_01_000001

hadoop - 在 Tez 和 Map reduce 中运行 "count(*) "时的行为差异