Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ public Schema record(Schema record, List<String> names, Iterable<Schema.Field> s

if (avroField != null) {
// if the expectedField has a defaultValue, but the avroField does not, we need to
// create a newField to copy over the non-null default value
// create a newField to copy over the non-null default value.
if (expectedField.hasDefaultValue() && !AvroSchemaUtil.hasNonNullDefaultValue(avroField)) {
Schema newFiledSchema = (expectedField.isOptional()) ?
AvroSchemaUtil.toOption(AvroSchemaUtil.convert(expectedField.type()), true) :
AvroSchemaUtil.convert(expectedField.type());
Schema.Field newField =
new Schema.Field(avroField.name(), newFiledSchema, avroField.doc(), expectedField.getDefaultValue());
new Schema.Field(avroField.name(), avroField.schema(), avroField.doc(), expectedField.getDefaultValue());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the avroField is nullable avro schema, and the default value here is not null, the constructed avro schema will be invalid, please still retain the logic of making AvroSchemaUtil.toOption with putting null the second element in the avro union.

newField.addProp(AvroSchemaUtil.FIELD_ID_PROP, expectedField.fieldId());
updatedFields.add(newField);
hasChange = true;
Expand Down