2013-02-02 31 views
0

我运行一个简单的Hadoop程序,我得到以下错误:MapReduce的用Hadoop类型匹配:

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

映射:

public static class myMapper extends Mapper<LongWritable, Text, Text, Text> 
public void map(LongWritable key, Text line,OutputCollector<Text,Text> output, Reporter reporter) throws IOException, InterruptedException 

减速机:

public static class triangleCounterReducer extends Reducer<Text, Text, Text, Text> 
public void reduce(Text key,Iterable<Text> line,OutputCollector<Text,Text> output,Reporter reporter) throws IOException, InterruptedException 

主营:

... 
job.setOutputKeyClass(Text.class); 
job.setOutputValueClass(Text.class); 
job.setMapOutputKeyClass(Text.class); 
job.setMapOutputValueClass(Text.class); 
... 

我该如何解决这个问题?

+0

你设置了mapper类吗?看起来你正在获得IdentityMapper输出。发布你的完整作业配置请 –

回答

0

看起来像使用新的API类(你映射器扩展mapred.Mapper)你的,但你必须使用旧的API(使用的是OutputCollector和记者)写您的地图方法

更改您的映射图签名和减速减少方法如下:

public void map(LongWritable key, Text value, Context context) { .. } 
public void reduce(Text key, Iterable<Text> value, Context context) { .. } 

它还帮助,如果您添加上面的方法,这将导致编译失败,如果你有错误的签名@Override注解。

+0

谢谢...我试过了......它工作的很棒! –