mirror of https://github.com/apache/nifi.git
NIFI-4030 Populating default values on GenericRecord from Avro schema if not present in RecordSchema
This closes #1896.
This commit is contained in:
parent
45e035686f
commit
b0c9428776
|
@ -273,6 +273,15 @@ public class AvroTypeUtil {
|
|||
rec.put(fieldName, converted);
|
||||
}
|
||||
|
||||
// see if the Avro schema has any fields that aren't in the RecordSchema, and if those fields have a default
|
||||
// value then we want to populate it in the GenericRecord being produced
|
||||
for (final Field field : avroSchema.getFields()) {
|
||||
final Optional<RecordField> recordField = recordSchema.getField(field.name());
|
||||
if (!recordField.isPresent() && rec.get(field.name()) == null && field.defaultVal() != null) {
|
||||
rec.put(field.name(), field.defaultVal());
|
||||
}
|
||||
}
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue