When I was trying the Map Reduce programming example from Hadoop in Action book based on Hadoop 0.20 API I got the error
java.io.IOException: Type mismatch in value from map: expected org.apache.hadoop.io.IntWritable, recieved org.apache.hadoop.io.Text
But as far as i checked i am passing everything properly. It would be really helpful if someone can help me with this.
Here is the code. Its the same code which is in the book.
@SuppressWarnings("unused")
public class CountPatents extends Configured implements Tool {
@SuppressWarnings("deprecation")
public static class MapClass extends MapReduceBase implements Mapper<Text, Text, Text, Text> {
public void map(Text key, Text value,OutputCollector<Text, Text> output,Reporter reporter) throws IOException {
output.collect(value, key);
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, Text, Text, IntWritable> {
public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int count=0;
while(values.hasNext()){
count=count+1;
values.next();
}
output.collect(key, new IntWritable(count));
}
}
public int run(String[] args) throws Exception {
Configuration conf = getConf();
JobConf job = new JobConf(conf, CountPatents.class);
Path in = new Path(args[0]);
Path out = new Path(args[1]);
FileInputFormat.setInputPaths(job, in);
FileOutputFormat.setOutputPath(job, out);
job.setJobName("MyJob");
job.setMapperClass(MapClass.class);
job.setReducerClass(Reduce.class);
job.setInputFormat(KeyValueTextInputFormat.class);
job.setOutputFormat(TextOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.set("key.value.separator.in.input.line", ",");
JobClient.runJob(job);
return 0;
}
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new CountPatents(), args);
System.exit(res);
}
}