跪求各位大神
为什么会出现这种问题呢?
为什么会出现这种问题呢?
2020-02-12
/创建静态内部类MyMapper
public static class MyMapper extends Mapper<LongWritable,Text,Text,LongWritable>{
//调用自带的map()函数
protected void map(LongWritable k1,Text v1,Context context)
throws IOException,InterruptedException{
//k1代表的是每一行的偏移量,v1代表的是每一行的内容
//将传送进来的每一行数据切割,切割成单词
String[] words =v1.toString().split(" ");
//迭代切割出来的单词数据
for(String word:words) {
//将迭代出来的单词数据封装成<k2,v2>
Text k2 =new Text(word);
LongWritable v2=new LongWritable();
//把<k2,v2>写出去
context.write(k2, v2);
}
}
}
//创建自定义静态内部类MyReducer
public static class MyReducer extends Reducer<Text,LongWritable,Text,LongWritable>{
/*
* 针对v2s做累加求和,并且最终把<k3,v3>写出去
*/
protected void reducer(Text k2,Iterable<LongWritable> v2s,Context context)
throws IOException,InterruptedException{
//创建一个表量sum来保存v2s的累加值
long sum=0;
for(LongWritable v2:v2s) {
sum=sum+v2.get();
}
//组装<k3,v3>
Text k3=k2;
LongWritable v3=new LongWritable(sum);
//把组装好的<k3,v3>写出去
context.write(k3, v3);
}
}
代码好像没什么问题?
举报