我最近运行了一个 Sqoop 作业,然后使用 AvroTools 提取avro文件的架构,然后将其编译为 Java 类。每当我尝试使用Avro对象时,都会收到以下ClassCastException:



我的 map 绘制者:

public class KNNMapper extends Mapper<AvroKey<PatientAvro>, NullWritable, LongWritable, PatientWritable> {

PatientWritable patient;
LongWritable providerKey;
Integer patientKey;
Integer lengthOfStay;
Integer msDrgGroup;
Integer age;

@Override
public void map(AvroKey<PatientAvro> patientAvro, NullWritable value, Context context) throws IOException, InterruptedException {



    patientKey = patientAvro.datum().getPatientKey();
    lengthOfStay = patientAvro.datum().getLengthOfStay();
    msDrgGroup = patientAvro.datum().getMsDrg();
    age = patientAvro.datum().getAge();
    patient = new PatientWritable();
    patient.set(new Long(patientKey), new Double((double) lengthOfStay), new Double((double) msDrgGroup), new Double((double)age));

    providerKey = new LongWritable(patientAvro.datum().getProviderKey());
    context.write(providerKey, patient);
}
}

任何帮助将不胜感激。

最佳答案

Sqoop自动创建Java和.avsc文件。您要分别创建它们吗?因此,如果仅使用生成的Java,就可以了。

关于java - 通用数据记录无法转换为Avro,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30987032/

10-10 11:18