MapReduce案例-wordcount-Reduce阶段代码

public class WordCountReducer extends

	Reducer<Text,LongWritable,Text,LongWritable> {
	
	/**
	* 自定义我们的reduce逻辑
	* 所有的key都是我们的单词,所有的values都是我们单词出现的次数
	* @param key
	* @param values
	* @param context
	* @throws IOException
	* @throws InterruptedException
	*/
	@Override
	protected void reduce(Text key, Iterable<LongWritable> values,
		Context context) throws IOException, InterruptedException {
		long count = 0;
		for (LongWritable value : values) {
			count += value.get();
		}
		context.write(key,new LongWritable(count));
	}
	
}
发布了2209 篇原创文章 · 获赞 50 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/Leon_Jinhai_Sun/article/details/104486308
今日推荐