@Override
public Object deserializeKeyAsColumnValueFromBytes(String fieldName,
byte[] columnKeyBytes, byte[] columnValueBytes) {
Field field = avroSchema.getAvroSchema().getField(fieldName);
if (field == null) {
throw new ValidationException("Invalid field name " + fieldName
+ " for schema " + avroSchema.toString());
}
Schema.Type schemaType = field.schema().getType();
if (schemaType == Schema.Type.MAP) {
DatumReader<Object> datumReader = fieldDatumReaders.get(fieldName);
if (datumReader == null) {
throw new ValidationException("No datum reader for field name: "
+ fieldName);
}
return AvroUtils.readAvroEntity(columnValueBytes, datumReader);
} else if (schemaType == Schema.Type.RECORD) {
if (!kacRecordDatumReaders.containsKey(fieldName)) {
throw new ValidationException("Invalid field name " + fieldName
+ " for schema " + avroSchema.toString());
}
String columnKey = new String(columnKeyBytes);
if (!kacRecordDatumReaders.get(fieldName).containsKey(columnKey)) {
throw new ValidationException("Invalid key in record: "
+ fieldName + "." + columnKey);
}
DatumReader<Object> datumReader = kacRecordDatumReaders.get(fieldName)
.get(columnKey);
return AvroUtils.readAvroEntity(columnValueBytes, datumReader);
} else {
throw new ValidationException("Unsupported type for keyAsColumn: "
+ schemaType);
}
}