在Hadoop Map-Reduce

时间:2018-03-10 14:27:24

标签: hadoop mapreduce

我正在尝试编写地图缩小工作,并希望在我的减速机上添加一个计数器。但是,当我运行作业时,计数器似乎没有出现在输出中。

目前我正在使用该行(Java):

context.getCounter(ReducerCounters.COUNTDISTINCT).increment(1);

说实话,我并非100%确定可以在减速机上使用这样的计数器。如果有人知道这是可能的还是不可能的,请告诉我。我似乎无法在网上找到任何可靠的减速器计数器示例。

非常感谢。

1 个答案:

答案 0 :(得分:1)

以下是我的导入:

import org.apache.hadoop.mapreduce.Counter;
import org.apache.hadoop.mapreduce.Counters;

这在我的驱动程序类中作为枚举出现。

 public enum ReducerCounters {
    COUNTDISTINCT
   };

这存在于我的驱动程序的运行功能中。

    job.waitForCompletion(true);
    Counters cn=job.getCounters();
    // Find the specific counters that you want to print
    Counter c1=cn.findCounter(ReducerCounters.COUNTDISTINCT);
    System.out.println("Displaying just the value " + c1.getValue());

还要确保在pom文件中使用最新的hadoop客户端版本。不要使用上次发布的hadoop-core版本,因为它没有更新。我刚试过它。计数器在我的mapper和reducer中都可以工作。

相关问题