hadoop reducer局部变量始终初始化

9w11ddsr  于 2021-06-03  发布在  Hadoop
关注(0)|答案(0)|浏览(248)

我在reducer类中有一个类变量:

  1. public static class ReduceClass extends
  2. Reducer<Text, IntWritable, Text, IntWritable> {
  3. int N = 0;
  4. @Override
  5. public void reduce(Text key, Iterable<IntWritable> values, Context context)
  6. throws IOException, InterruptedException {
  7. int sum = 0;
  8. for (IntWritable value : values) {
  9. sum += value.get();
  10. }
  11. if (key.equals(something))
  12. {
  13. N += sum;
  14. }
  15. else
  16. {
  17. if(N > 0) context.write(key, new IntWritable(N));
  18. else //write something else
  19. }
  20. }
  21. }

然而,即使'key.equals(something)'满足(它至少满足一次,肯定),在reduce函数调用之间,n始终是0。
有趣的是,如果我在函数的开头加上'n++',n的值在reduce调用之间确实是递增的,但是'n+=sum'根本不起作用!就像它从不执行一样。
我做错什么了?我只需要n在reduce调用之间保持它的值。当然是每个减速机。
蒂亚。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题