Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-19291

Fix exception for AvroSchemaConverter#convertToSchema when RowType contains multiple row fields

    XMLWordPrintableJSON

    Details

      Description

      Hi, I use `AvroSchemaConverter` to converts flink logical type into an avro schema will be throw `SchemaParseException` when there are multiple row type fields and the field names in each row type are different

       

      This is my simplified code

      RowType rowType = (RowType) TableSchema.builder()
       .field("row1", DataTypes.ROW(DataTypes.FIELD("a", DataTypes.STRING())))
       .field("row2", DataTypes.ROW(DataTypes.FIELD("b", DataTypes.STRING())))
       .build().toRowDataType().getLogicalType();
      Schema schema = AvroSchemaConverter.convertToSchema(rowType);
      System.out.println(schema.toString(true));
      

       

      it will throw

      org.apache.avro.SchemaParseException: Can't redefine: row_1
      
      at org.apache.avro.Schema$Names.put(Schema.java:1128) 
      at org.apache.avro.Schema$NamedSchema.writeNameRef(Schema.java:562) 
      at org.apache.avro.Schema$RecordSchema.toJson(Schema.java:690) 
      at org.apache.avro.Schema$ArraySchema.toJson(Schema.java:805) 
      at org.apache.avro.Schema$UnionSchema.toJson(Schema.java:882) 
      at org.apache.avro.Schema$RecordSchema.fieldsToJson(Schema.java:716) 
      at org.apache.avro.Schema$RecordSchema.toJson(Schema.java:701) 
      at org.apache.avro.Schema.toString(Schema.java:324) 
      at org.apache.avro.Schema.toString(Schema.java:314) 
      at java.lang.String.valueOf(String.java:2994) 
      at java.io.PrintStream.println(PrintStream.java:821) 
      at org.apache.flink.formats.avro.typeutils.AvroSchemaConverterTest.testRowTypeAvroSchemaConversion(AvroSchemaConverterTest.java:99) 
      at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
       

      Thanks!
       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                xiaozilong xiaozilong
                Reporter:
                xiaozilong xiaozilong
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: