【发布时间】:2015-06-22 18:17:24
【问题描述】:
我最近运行了一个 Sqoop 作业,然后使用 AvroTools 提取 avro 文件的架构,然后将其编译为 Java强>类。每当我尝试使用 Avro 对象时,都会收到以下 ClassCastException:
java.lang.Exception: java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record 不能转换为 com.xxx.xxx.patient_avro.PatientAvro 在 org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462) 在 org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522) 引起:java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record 不能转换为 com.xxx.xxx.patient_avro.PatientAvro 在 com.xxx.xxx.knn_mapreduce.KNNMapper.map(KNNMapper.java:28) 在 com.xxx.xxx.knn_mapreduce.KNNMapper.map(KNNMapper.java:14) 在 org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146) 在 org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787) 在 org.apache.hadoop。 mapred.MapTask.run(MapTask.java:341)
我的映射器:
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);
}
}
任何帮助将不胜感激。
【问题讨论】:
-
你能发布在你的 pom.xml 中使用的依赖项吗?您是在正常执行还是执行 MRUnit 时遇到此错误?
标签: java hadoop mapreduce avro mapper