mirror of https://github.com/apache/nifi.git
NIFI-3879: Allow null Avro default values
- Avro uses their own class for null values, so a standard check against null isn't picking them up. This closes #1792.
This commit is contained in:
parent
e9848f4276
commit
382eef2183
|
@ -25,6 +25,7 @@ import org.apache.avro.generic.GenericData;
|
|||
import org.apache.avro.generic.GenericFixed;
|
||||
import org.apache.avro.generic.GenericRecord;
|
||||
import org.apache.avro.util.Utf8;
|
||||
import org.apache.avro.JsonProperties;
|
||||
import org.apache.nifi.schema.access.SchemaNotFoundException;
|
||||
import org.apache.nifi.serialization.SimpleRecordSchema;
|
||||
import org.apache.nifi.serialization.record.DataType;
|
||||
|
@ -205,8 +206,12 @@ public class AvroTypeUtil {
|
|||
final String fieldName = field.name();
|
||||
final DataType dataType = AvroTypeUtil.determineDataType(field.schema());
|
||||
|
||||
if (field.defaultVal() == JsonProperties.NULL_VALUE) {
|
||||
recordFields.add(new RecordField(fieldName, dataType, field.aliases()));
|
||||
} else {
|
||||
recordFields.add(new RecordField(fieldName, dataType, field.defaultVal(), field.aliases()));
|
||||
}
|
||||
}
|
||||
|
||||
final RecordSchema recordSchema = new SimpleRecordSchema(recordFields, schemaText, AVRO_SCHEMA_FORMAT, schemaId);
|
||||
return recordSchema;
|
||||
|
|
Loading…
Reference in New Issue