2013-02-02 32 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

謝謝...我試過了......它工作的很棒! –