Sri*_*Sri 1 eclipse reduce hadoop map
当我在基于Hadoop 0.20 API的Hadoop in Action手册中尝试Map Reduce编程示例时,我收到了错误
java.io.IOException:从map中键入不匹配的值:expected org.apache.hadoop.io.IntWritable,recieved org.apache.hadoop.io.Text
但据我检查,我正在通过一切正常.如果有人可以帮助我,这将是非常有帮助的.
这是代码.它与书中的代码相同.
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
从快速查看(不在本地运行代码),看起来您在设置时将作业的输出设置为Text类型job.setOutputValueClass(Text.class);,但reducer上的输出类型设置为IntWritable.这可能是错误.
| 归档时间: |
|
| 查看次数: |
2632 次 |
| 最近记录: |