我需要从我的reducer中的mapper访问计数器.这可能吗?如果是这样怎么办?
举个例子:我的映射器是:
public class CounterMapper extends Mapper<Text,Text,Text,Text> {
static enum TestCounters { TEST }
@Override
protected void map(Text key, Text value, Context context)
throws IOException, InterruptedException {
context.getCounter(TestCounters.TEST).increment(1);
context.write(key, value);
}
}
Run Code Online (Sandbox Code Playgroud)
我的减速机是
public class CounterReducer extends Reducer<Text,Text,Text,LongWritable> {
@Override
protected void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
Counter counter = context.getCounter(CounterMapper.TestCounters.TEST);
long counterValue = counter.getValue();
context.write(key, new LongWritable(counterValue));
}
}
Run Code Online (Sandbox Code Playgroud)
counterValue总是0.我做错了什么或这是不可能的?