public Object buildKeyAsColumnField(String fieldName,
Map<CharSequence, Object> keyAsColumnValues) {
Schema schema = avroSchema.getAvroSchema();
Field field = schema.getField(fieldName);
if (field == null) {
throw new ValidationException("No field named " + fieldName
+ " in schema " + schema);
}
Schema.Type fieldType = field.schema().getType();
if (fieldType == Schema.Type.MAP) {
Map<CharSequence, Object> retMap = new HashMap<CharSequence, Object>();
for (Entry<CharSequence, Object> entry : keyAsColumnValues.entrySet()) {
retMap.put(entry.getKey(), entry.getValue());
}
return retMap;
} else if (fieldType == Schema.Type.RECORD) {
AvroRecordBuilder<E> builder = kacRecordBuilderFactories.get(fieldName)
.getBuilder();
for (Entry<CharSequence, Object> keyAsColumnEntry : keyAsColumnValues
.entrySet()) {
builder.put(keyAsColumnEntry.getKey().toString(),
keyAsColumnEntry.getValue());
}
return builder.build();
} else {
throw new ValidationException(
"Only MAP or RECORD type valid for keyAsColumn fields. Found "
+ fieldType);
}
}