我有一个简单的mapreduce工作,我从avro网站借了一些小修改(我删除了reducer)。它基本上需要一个简单的avro文件作为输入。以下是avro文件的模式
avro架构:
{
"type": "record",
"name": "User",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number", "type": "int"},
{"name":"favorite_color", "type": "string"}
]
}
以下是我的mapreduce工作(Map器和主要功能):
public class ColorCountMapper extends Mapper<AvroKey<User>, NullWritable, Text, IntWritable> {
@Override
public void map(AvroKey<User> key, NullWritable value, Context context) throws IOException, InterruptedException {
CharSequence color = key.datum().getFavoriteColor();
if (color == null) {
color = "none";
}
context.write(new Text(color.toString()), new IntWritable(1));
}
}
和
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "TestColor");
job.setJarByClass(runClass.class);
job.setJobName("Color Count");
FileInputFormat.setInputPaths(job, new Path("in"));
FileOutputFormat.setOutputPath(job, new Path("out"));
job.setInputFormatClass(AvroKeyInputFormat.class);
job.setMapperClass(ColorCountMapper.class);
AvroJob.setInputKeySchema(job, User.getClassSchema());
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
boolean r = job.waitForCompletion(true);
System.out.println(r);
}
当我运行程序时,它返回false并且没有成功。我搞不懂这个问题。有人能帮忙吗?
1条答案
按热度按时间lh80um4z1#
已将Map器的值类型设置为nullwritable。然后在main/driver中将map输出值类设置为intwritable。Map器中的值类型和主/驱动程序应该相同。相应地修改程序。如果你有解决办法,请接受我的回答。