hadoop reducer不执行问题及解决

一、问题描述:

在eclipse上通过hadoop插件自动生成mapper、reducer、main方法类实现wordcount的统计。

待处理的文件内容:

hello tom
hello joy
hello rose
hello joy
hello jerry
hello tom
hello rose

hello joy

测试了几次,处理的结果都为:

hello 1
hello 1
hello 1
hello 1
hello 1
hello 1
hello 1
hello 1
jerry 1
joy 1
joy 1
joy 1
rose 1
rose 1
tom 1

tom 1

并没有实现到按单词统计出现次数的结果。

二、问题分析

1、从上面你的结果分析,reducer根本没有起作用,但是程序却能运行无报错

2、在reducer中增加一些相应的打印语句,也无输出,确认reducer是没有执行到,分析了很久也没有找到问题所在

3、上网搜索了一下,找到了问题所在

https://blog.csdn.net/world_java/article/details/17427631

三、问题解决

1、有问题的reducer类定义,无报错(但实际调用了默认的reduce方法处理)

2、reduce方法增加@override后,出现报错


3、检查后发现是Reducer的参数有问题Iterable<LongWritable>,修改为LongWritable后,错误消除

4、执行结果

hello 8
jerry 1
joy 3
rose 2

tom 2

建议在重写方法时加入@override,这样可以检测出重写错误。

猜你喜欢

转载自blog.csdn.net/Jay7925417/article/details/80226052
今日推荐