我无法获得结果中的reduce值,只能得到密钥

时间:2017-08-10 07:13:46

标签: hadoop mapreduce

在地图功能中,我希望得到像 hello world 1

的结果
context.write(new Text(firstStr + "\t" + secondStr), new LongWritable(1));

在我的reduce函数中,

private LongWritable result = new LongWritable();
public void reduce(Text key, Iterable<LongWritable> values,Context context) throws IOException, InterruptedException {

      long sum = 0;
      for (LongWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      //context.write(new Text(key.toString().getBytes("GB18030")), result);
      context.write(key, result);
}

在我的结果中,我发现我的部分-r-00000中的数据是这样的:

hello  world
hello  tom
thank  you

实际上,我想得到的结果如下

hello  world  1
hello  tom   1

我不知道发生了什么事,请帮帮我?感谢

0 个答案:

没有答案