当前位置: 首页 > 知识库问答 >
问题:

常规数据记录不能强制转换为Avro

华修永
2023-03-14

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

我的映射器:

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);
}
}

如有任何帮助,将不胜感激。

共有1个答案

司空实
2023-03-14

Sqoop自动创建Java和.avsc文件。你是单独创建它们吗?。因此,如果您只是使用生成的Java就可以了。

 类似资料: