Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -186,12 +186,19 @@ private InternalSchema toInternalSchema(
List<InternalField> subFields = new ArrayList<>(schema.getFields().size());
for (Schema.Field avroField : schema.getFields()) {
IdMapping idMapping = fieldNameToIdMapping.get(avroField.name());
String fieldDoc = avroField.doc();
if (fieldDoc == null) {
fieldDoc = avroField.getProp("comment");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a legacy way of adding docs to avro?

}
InternalSchema subFieldSchema =
toInternalSchema(
avroField.schema(),
SchemaUtils.getFullyQualifiedPath(parentPath, avroField.name()),
getChildIdMap(idMapping));
Object defaultValue = getDefaultValue(avroField);
if (fieldDoc != null && subFieldSchema.getComment() == null) {
subFieldSchema = InternalSchema.builderFrom(subFieldSchema).comment(fieldDoc).build();
}
subFields.add(
InternalField.builder()
.parentPath(parentPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,4 +889,25 @@ public void testIcebergToAvroUUIDSupport() {
assertEquals(
internalSchema, AvroSchemaConverter.getInstance().toInternalSchema(avroRepresentation));
}

@Test
public void testExtractFieldCommentsFromAvroDocOrProp() {
Schema avroRepresentation =
new Schema.Parser()
.parse(
"{\"type\":\"record\",\"name\":\"commentRecord\",\"fields\":["
+ "{\"name\":\"withDoc\",\"type\":\"string\",\"doc\":\"doc comment\"},"
+ "{\"name\":\"withProp\",\"type\":\"int\",\"comment\":\"prop comment\"}"
+ "]}");

InternalSchema internalSchema =
AvroSchemaConverter.getInstance().toInternalSchema(avroRepresentation);

Map<String, InternalField> fieldsByName =
internalSchema.getFields().stream()
.collect(java.util.stream.Collectors.toMap(InternalField::getName, f -> f));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use an import instead of the fully qualified path


assertEquals("doc comment", fieldsByName.get("withDoc").getSchema().getComment());
assertEquals("prop comment", fieldsByName.get("withProp").getSchema().getComment());
}
}