hadoop 2.6.0和avro

hadoop 2.6.0和avro,hadoop,avro,Hadoop,Avro,我正在尝试使用avro运行map reduce,但在尝试了网络上人们建议的所有选项后,我仍然无法通过- 2009年11月15日21:54:48警告映射。本地JobRunner:job_local1421922570_0001 java.lang.Exception:java.lang.NoSuchMethodError:org.apache.avro.generic.GenericData.createDatumWriter(Lorg/apache/avro/Schema;)Lorg/apach

我正在尝试使用avro运行map reduce,但在尝试了网络上人们建议的所有选项后,我仍然无法通过-

2009年11月15日21:54:48警告映射。本地JobRunner:job_local1421922570_0001 java.lang.Exception:java.lang.NoSuchMethodError:org.apache.avro.generic.GenericData.createDatumWriter(Lorg/apache/avro/Schema;)Lorg/apache/avro/io/DatumWriter

下面是代码(来自Hadoop权威指南) 公共类AvroGenericMapTemperature扩展配置的实现工具{

private static final Schema SCHEMA = new Schema.Parser().parse(
    "{" +
    " \"type\" : \"record\"," +
    " \"name\" : \"WeatherRecord\"," +
    " \"doc\" : \"A weather reading\"," +
    " \"fields\": [" +
    "    {\"name\": \"year\", \"type\": \"int\" }," +
    "    {\"name\": \"temperature\", \"type\": \"int\" }," +
    "    {\"name\": \"stationId\", \"type\": \"string\" }" +
    "  ]" +
    "}"
);

public static class MaxTemperatureMapper extends 
    Mapper<LongWritable,  Text, 
    AvroKey<Integer>,AvroValue<GenericRecord> > {
    private NcdcRecordParser parser = new NcdcRecordParser();
    private GenericRecord record = new GenericData.Record(SCHEMA);

    @Override
    protected void map(
        LongWritable key,
        Text value,
        Mapper<LongWritable, Text, AvroKey<Integer>, 
        AvroValue<GenericRecord>>.Context context)
        throws IOException, InterruptedException {
        parser.parse(value.toString());

        if( parser.isValidTemperature() ) {
            record.put("year", parser.getYearInt());
            record.put("temperature", parser.getAirTemperature());
            record.put("stationId", parser.getStationId());
            context.write(new AvroKey<Integer>(parser.getYearInt()), 
            new AvroValue<GenericRecord>(record));
        }
    }
}

public static class MaxTemperatureReducer extends 
Reducer<AvroKey<Integer>, AvroKey<GenericRecord>, 
AvroKey<GenericRecord>, NullWritable> {

    @Override
    protected void reduce(
        AvroKey<Integer> key,
        Iterable<AvroKey<GenericRecord>> values,
        Reducer<AvroKey<Integer>, AvroKey<GenericRecord>, 
        AvroKey<GenericRecord>, NullWritable>.Context context)
        throws IOException, InterruptedException {
        GenericRecord max = null;

        for ( AvroKey<GenericRecord> value : values) {
            GenericRecord record = value.datum();
            if ( max == null ||
                 (Integer)record.get("temperature") > (Integer) 
                 max.get("termperature") ) {
                 max = newWeatherRecord(record);
            }
        }
        context.write(new AvroKey<GenericRecord>(max), 
        NullWritable.get());
    }

    private GenericRecord newWeatherRecord(GenericRecord value) {
        GenericRecord record = new GenericData.Record(SCHEMA);
        record.put("year", value.get("year"));
        record.put("temperature", value.get("temperature"));
        record.put("stationId", value.get("stationId"));
        return record;
    }
}

public int run(String[] args) throws Exception {
    // TODO Auto-generated method stub
    Job job = new Job( getConf(), "Avro mapreduce");
    job.setJarByClass(getClass());


    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    AvroJob.setMapOutputKeySchema(job, Schema.create(Schema.Type.INT));
    AvroJob.setMapOutputValueSchema(job, SCHEMA);
    AvroJob.setOutputKeySchema(job, SCHEMA);

    job.setInputFormatClass(TextInputFormat.class);
    job.setOutputFormatClass(AvroKeyOutputFormat.class);

    job.setMapperClass(MaxTemperatureMapper.class);
    job.setReducerClass(MaxTemperatureReducer.class);

    job.waitForCompletion(true);
    return 0;
}

public static void main(String[] args) throws Exception {
    int exitcode = 
        ToolRunner.run(new AvroGenericMapTemperature(), args);
}
private static final Schema Schema=new Schema.Parser().parse(
"{" +
“\”类型\“:\”记录\“+
“\”名称\“:\”天气记录\“+
“\'doc\:\'A weather reading\”,”+
“\”字段\:[”+
“{\'name\':\'year\',\'type\':\'int\'”+
“{\'name\':\'temperature\',\'type\':\'int\'”+
{\'name\':\'stationId\',\'type\':\'string\'}+
"  ]" +
"}"
);
公共静态类MaxTemperatureMapper扩展
制图员{
专用NcdcRecordParser parser=新的NcdcRecordParser();
私有GenericRecord=新的GenericData.record(模式);
@凌驾
受保护的空图(
长可写密钥,
文本值,
Mapper.Context(上下文)
抛出IOException、InterruptedException{
parser.parse(value.toString());
if(parser.isValidTemperature()){
record.put(“year”,parser.getYearInt());
record.put(“temperature”,parser.getairtimperature());
put(“stationId”,parser.getStationId());
write(新的AvroKey(parser.getYearInt()),
新的AvroValue(记录));
}
}
}
公共静态类MaxTemperatureReducer扩展
减速器{
@凌驾
保护空洞减少(
AvroKey键,
可比值,
(上下文)
抛出IOException、InterruptedException{
GenericRecord max=null;
用于(AvroKey值:值){
GenericRecord记录=value.datum();
如果(max==null||
(整数)记录。获取(“温度”)>(整数)
最大温度(“温度”)){
最大值=新天气记录(记录);
}
}
context.write(新的AvroKey(max),
NullWritable.get());
}
专用GenericRecord newWeatherRecord(GenericRecord值){
GenericRecord=新的GenericData.record(模式);
记录.put(“年”),值.get(“年”);
记录.put(“温度”),值.get(“温度”);
record.put(“stationId”),value.get(“stationId”);
返回记录;
}
}
公共int运行(字符串[]args)引发异常{
//TODO自动生成的方法存根
Job Job=新作业(getConf(),“Avro-mapreduce”);
setJarByClass(getClass());
addInputPath(作业,新路径(args[0]);
setOutputPath(作业,新路径(args[1]);
setMapOutputKeySchema(作业,Schema.create(Schema.Type.INT));
setMapOutputValueSchema(作业,模式);
setOutputKeySchema(作业,模式);
setInputFormatClass(TextInputFormat.class);
setOutputFormatClass(AvroKeyOutputFormat.class);
setMapperClass(MaxTemperatureMapper.class);
job.setReducerClass(MaxTemperatureReducer.class);
job.waitForCompletion(true);
返回0;
}
公共静态void main(字符串[]args)引发异常{
int exitcode=
运行(新的AvroGenericMapTemperature(),args);
}
});
我已经在HADOOP_类路径中显式设置了所有avro JAR(1.7.5版本的avro、avro mapred、avro tools等),并且在运行上述操作时还指定了-D mapreduce.job.user.CLASSPATH.first=true,但我一直收到相同的错误。。。。我知道hadoop 2.6.0的默认avro版本是1.7.4,我甚至尝试过avro的版本,但没有成功。。。。任何帮助都是巨大的

减速器的通用参数如下:

第一个和第二个分别是KeyIn和Value-in。 所以你可以试着换衣服 公共静态类MaxTemperatureReducer扩展 减速器,AvroKey, AvroKey,可空写>{

@Override
protected void reduce(
    AvroKey<Integer> key,
    Iterable<AvroKey<GenericRecord>> values,
    Reducer<AvroKey<Integer>, AvroKey<GenericRecord>, 
    AvroKey<GenericRecord>, NullWritable>.Context context)
    throws IOException, InterruptedException {
@Override
protected void reduce(
    AvroKey<Integer> key,
    Iterable<AvroKey<GenericRecord>> values,
    Reducer<AvroKey<Integer>, AvroValue<GenericRecord>, 
    AvroKey<GenericRecord>, NullWritable>.Context context)
    throws IOException, InterruptedException {
@覆盖
保护空洞减少(
AvroKey键,
可比值,
(上下文)
抛出IOException、InterruptedException{
到 公共静态类MaxTemperatureReducer扩展 减速器,AvroValue, AvroKey,可空写>{

@Override
protected void reduce(
    AvroKey<Integer> key,
    Iterable<AvroKey<GenericRecord>> values,
    Reducer<AvroKey<Integer>, AvroKey<GenericRecord>, 
    AvroKey<GenericRecord>, NullWritable>.Context context)
    throws IOException, InterruptedException {
@Override
protected void reduce(
    AvroKey<Integer> key,
    Iterable<AvroKey<GenericRecord>> values,
    Reducer<AvroKey<Integer>, AvroValue<GenericRecord>, 
    AvroKey<GenericRecord>, NullWritable>.Context context)
    throws IOException, InterruptedException {
@覆盖
保护空洞减少(
AvroKey键,
可比值,
(上下文)
抛出IOException、InterruptedException{
因为在映射器中,您将AvroKey作为键,AvroValue作为值