Mapper
public class workcountmapper extends Mapper<LongWritable, Text,Text, IntWritable> {
Text outk =new Text();
IntWritable outv=new IntWritable(1);
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//获取一行数据
final String line = value.toString();
//切割
final String[] work = line.split(" ");
//遍历输出
for (String s : work) {
outk.set(s);
context.write(outk,outv);
}
}
}
reduce
public class workcountreduce extends Reducer<Text, IntWritable,Text,IntWritable> {
IntWritable outk=new IntWritable();
@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum=0;
for (IntWritable value : values) {
sum