Type mismatch in key from map: expected org.apache.hadoop.io.Text, received org.apache.hadoop.io.LongWritable

  今天在写MapReduce时遇到了这个问题,这个问题的解释是:来自map的键类型不匹配:expected org.apache.hadoop.io文本,收到org.apache.hadoop.io.LongWritable,也就是说从map到reduce的输出格式装换错误,或者没有定义,即使在你的map的输出参数写的和reduce的参数一模一样还是会出现这个错误。

  

     那么解决的办法就是既然他自己识别不了,我们就强制给他装换,给他设置类型参数,这样就可以了。

  

        //设置map输出的key类型
        job.setMapOutputKeyClass(LongWritable.class);
        //设置map输出的value类型
        job.setMapOutputValueClass(Text.class);
        //设置输出的key类型
        job.setOutputKeyClass(Text.class);
        //设置输出的value类型
        job.setOutputValueClass(NullWritable.class);        

  我们自己手动设定map的输出key 和 value 的类型。问题解决。

猜你喜欢

转载自www.cnblogs.com/zll20153246/p/9351167.html
今日推荐