MR IOException: Type mismatch in key from map的处理

一、错误描述

    执行MR出现如下错误,如执行命令是:

hadoop jar /opt/cloudera/parcels/CDH-5.0.1-1.cdh5.0.1.p0.47/lib/hadoop-mapreduce/hadoop-streaming-2.3.0-cdh5.0.1.jar -input /test2 -output /test12 -mapper org.apache.hadoop.mapred.lib.TokenCountMapper -reducer org.apache.hadoop.mapred.lib.LongSumReducer -jobconf mapred.job.name='java mr' -numReduceTasks 1

    错误如下:

14/06/09 15:09:50 INFO mapreduce.Job: Task Id : attempt_1401948435703_0028_m_000000_0, Status : FAILED
Error: java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.LongWritable, received org.apache.hadoop.io.Text
        at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1049)
        at org.apache.hadoop.mapred.MapTask$OldOutputCollector.collect(MapTask.java:587)
        at org.apache.hadoop.mapred.lib.TokenCountMapper.map(TokenCountMapper.java:54)
        at org.apache.hadoop.mapred.lib.TokenCountMapper.map(TokenCountMapper.java:38)
        at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54)
        at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:430)
        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:342)
        at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:168)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:415)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1548)
        at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:163)

二、原因及解决方案

    1、map和reduce中的输入输出格式不对。

    2、新旧api混用。你的map()方法 没有按新api写, 结果系统不认为它是一个重载,而是一个新方法,不会被调用。

    解决办法:在的map(), reduce()前面加上@Override,并按照新的API来写map(), reduce()。

你可能感兴趣的:(mapreduce,type,mr,IOException,mismatch)