wuchong commented on a change in pull request #13472:
URL: https://github.com/apache/flink/pull/13472#discussion_r502734646
##########
File path:
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSchemaConverter.java
##########
@@ -359,13 +359,13 @@ public static Schema convertToSchema(LogicalType
logicalType, int rowTypeCounter
// we have to make sure the record name is
different in a Schema
SchemaBuilder.FieldAssembler<Schema> builder =
SchemaBuilder
.builder()
- .record("row_" + rowTypeCounter)
+ .record(rowName)
.fields();
- rowTypeCounter++;
for (int i = 0; i < rowType.getFieldCount();
i++) {
+ String fieldName = fieldNames.get(i);
builder = builder
- .name(fieldNames.get(i))
-
.type(convertToSchema(rowType.getTypeAt(i), rowTypeCounter))
+ .name(fieldName)
+
.type(convertToSchema(rowType.getTypeAt(i), fieldName))
Review comment:
However, if the parant field name is the same to the child name, there
still will be an avro exception. For example, the following example is still
failed:
```java
@Test
public void test() {
RowType rowType = (RowType) TableSchema.builder()
.field("row1", DataTypes.ROW(DataTypes.FIELD("a",
DataTypes.STRING())))
.field("row2", DataTypes.ROW(DataTypes.FIELD("b",
DataTypes.STRING())))
.field("row3", DataTypes.ROW(
DataTypes.FIELD("row3",
DataTypes.ROW(DataTypes.FIELD("c", DataTypes.STRING())))))
.build().toRowDataType().getLogicalType();
Schema schema = AvroSchemaConverter.convertToSchema(rowType);
System.out.println(schema.toString(true));
}
```
This can be fixed by concating parant and child name:
```java
String fieldName = rowName + "_" + fieldNames.get(i);
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]