Когда я пробовал пример программирования Map Reduce из Hadoop в книге действий на основе API Hadoop 0.20, я получил ошибку
java.io.IOException: несоответствие типа значения карте
Но насколько я проверил, я передаю все правильно. Было бы очень полезно, если бы кто-то мог помочь мне с этим.
Вот код. Это тот же код, который есть в книге.
@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);
}
}