MapReduce与Hadoop:类型不匹配

时间:2013-02-02 19:39:50

标签: 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);
...

我该如何解决这个????

1 个答案:

答案 0 :(得分:0)

看起来你正在使用新的API类(mapper扩展了mapred.Mapper),但是你已经使用旧的API编写了map方法(你正在使用OutputCollector和Reporter)

将mapper map signature和reducer reduce方法更改为以下内容:

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

如果在方法上方添加@Override注释,这也会有所帮助,如果您的签名错误,将导致编译器失败。