【问题标题】:XSD to Avro Conversion - SchemaParseException: can't redefine roleNotesGroupXSD 到 Avro 的转换 - SchemaParseException:无法重新定义 roleNotesGroup
【发布时间】:2020-04-21 05:53:58
【问题描述】:

我正在努力将 xsd 转换为 avro 架构

XSD sn-p:

<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>

我正在使用

Schema schema = Schema.createRecord(name, null, null, false); 

创建一个 avro 模式记录。 在上面的 xsd 中,roleNotesGroup 是 roleNotesSubGroup 的子代,它是 roleNotesGroup 的子代。 我可以递归地获取 avro 架构,直到 roleNotesSubGroup 然后将其转换为列表。

List<Schema.Field> is obtained recursively.

现在的问题是当我尝试将形成的字段添加到头元素 roleNotesGroup 时使用

Schema schema = Schema.createRecord(name, null, null, false);
schema.setFields(schemaFields);

我收到以下错误: SchemaParseException: 无法重新定义 roleNotesGroup

在 avro 或 avro 转换中是否有任何限制不能再次出现相同的名称?

【问题讨论】:

    标签: java json xsd avro


    【解决方案1】:

    从 apache jira 得到答案。 解决方案是为该重复元素使用不同的命名空间(由 apache 建议)或使用别名(对我有用)。

    https://issues.apache.org/jira/browse/AVRO-2809

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 2013-09-08
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      相关资源
      最近更新 更多