I am working on converting xsd to avro schema
XSD snippet:
<xsd:element name="roleNotesGroup">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="roleNotesSubGroup" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="roleNotesGroup" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="roleNotes" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:appinfo>
<source application="CUSTOMER" field="REL.CUSTOMER"/>
<fieldPiiAttribute value="INDIRECT"/>
<fieldPiiPurpose value="LEGITIMATE"/>
<fieldPiiEraseOption value="NO.ACTION"/>
<fieldPiiAccessibility value="ACCESS PORTABLE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="index" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="index" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="index" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
I am using
Schema schema = Schema.createRecord(name, null, null, false);
to create a avro schema record. In the above xsd roleNotesGroup is a child of roleNotesSubGroup which is a child of roleNotesGroup. I can recursively obtain the avro schema till roleNotesSubGroup which is then converted to list.
List<Schema.Field> is obtained recursively.
Now the problem is when i try to add the Fields formed to the head element roleNotesGroup using
Schema schema = Schema.createRecord(name, null, null, false);
schema.setFields(schemaFields);
I get the following error : SchemaParseException: can't redefine roleNotesGroup
Is there any restriction in avro or avro conversion that the same names should not occur again?
Got an answer from apache jira. The solution would be to use a different namespace ( suggested by apache ) for that recurring elements or using aliases ( works for me ).