【发布时间】:2012-06-16 05:42:26
【问题描述】:
如何将 Mapper 中收集的少量元数据传递给 Reducer?在我的具体问题中,我只想传递两个 long 值,因此我不会为这些值使用 MultipleOutputFormat 或 MultipleOutputs。
我尝试过的一些变体:
(1)
映射器
context.getCounter("Countergroup", "Counter").increment(1);
减速器
counter = context.getCounter("Countergroup", "Counter").getValue();
计数器不会定期更新,因此 Reducer 中的函数调用会产生 0 值。
(2)
映射器
context.getConfiguration().setInt("Counter", countTotal);
减速器
counter = context.getConfiguration().getInt("Counter", 0);
在运行作业期间当然不能更改配置(值得一试)。
已经有关于这个问题的问题,但我找不到有效的答案。此外,API 也发生了变化。我正在使用 Hadoop 0.20.2。
类似的问题:
Passing values from Mapper to Reducer
Accessing a mapper's counter from a reducer (这看起来很有希望,但它似乎不适用于 0.20.2 API)
【问题讨论】: