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