我不能得到result中reduce的值,只能得到key

lbsnaicq  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(257)

在map函数中,我想得到像hello world 1这样的结果

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

在我的reduce函数中,

  1. private LongWritable result = new LongWritable();
  2. public void reduce(Text key, Iterable<LongWritable> values,Context context) throws IOException, InterruptedException {
  3. long sum = 0;
  4. for (LongWritable val : values) {
  5. sum += val.get();
  6. }
  7. result.set(sum);
  8. //context.write(new Text(key.toString().getBytes("GB18030")), result);
  9. context.write(key, result);
  10. }

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

  1. hello world
  2. hello tom
  3. thank you

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

  1. hello world 1
  2. hello tom 1

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

暂无答案!

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

相关问题