问答详情
源自:5-4 WordCount代码开发

跪求各位大神

http://img4.mukewang.com/5e43935d0001db4405650100.jpg


为什么会出现这种问题呢?

提问者:qq_慕斯2033129 2020-02-12 13:57

个回答

  • qq_慕容2355427
    2020-02-26 19:17:33

    http://img4.mukewang.com/5e5653910001824a06490151.jpg大佬们,本人刚刚接触hadoop就遇到这个,这个问题我太头疼了,大佬们请帮我一下!!!

  • qq_慕斯2033129
    2020-02-12 21:20:09

    /创建静态内部类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);

    }

    }

    代码好像没什么问题?

  • 0CJJ0
    2020-02-12 17:01:27

    我猜你的map的初始值是0吧?而且reduce没有求和,检查一下你的代码?