import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; /* * Text 输入的字符串类型,序列化 * IntWritable 输入一串1,序列化 * Text 输出的字符串类型,序列化 * IntWritable 输出的求和数组,序列化*/ public class WordCountReduce extends Reducer<Text, IntWritable,Text,IntWritable> {//IntWritable序列化 /* * key 输入单词名字 * values 输入一串1 * content 用于输出的工具*/ @Override protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { //求和 int sum=0; for(IntWritable number:values){//不能写int要写IntWritable //遍历一群1 sum += number.get(); } context.write(key,new IntWritable(sum));//sum是int型,没有序列化,不能直接输出,所以写成new IntWritable(sum) } }
WordCount.java
import org.apache.hadoop.conf.Configuration; import or