"值"导致架构生成中出现问题

时间:2018-01-17 01:20:30

标签: apache-nifi avro

我有一个这样的对象:

"Meta": {
    "Type": 10,
    "Key": "Meta",
    "Value": {     <================ This is the "Value" in question
        "ElementType": {
            "Type": 2,
            "Key": "ElementType",
            "Value": "P"
        },
        "Attributes": {
            "Type": 9,
            "Key": "Attributes",
            "Value": [{
                "Type": 2,
                "Key": "ID",
                "Value": "cat"
            },
            {
                "Type": 2,
                "Key": "Class",
                "Value": ""
            }],
            "ContentType": 2
        }
    }
}

当我尝试从中生成Avro架构时,它会抛出错误。 如果我更改&#34; Value&#34;的第一个实例对于一个有目的的拼写错误(我使用&#34; Valuz&#34;),然后架构解析得很好。

这是对象(&#34; Valuz&#34;替换)

"Meta": {
    "Type": 10,
    "Key": "Meta",
    "Valuz": {     <================ Note this substitution
        "ElementType": {
            "Type": 2,
            "Key": "ElementType",
            "Value": "P"
        },
        "Attributes": {
            "Type": 9,
            "Key": "Attributes",
            "Value": [{
                "Type": 2,
                "Key": "ID",
                "Value": "cat"
            },
            {
                "Type": 2,
                "Key": "Class",
                "Value": ""
            }],
            "ContentType": 2
        }
    }
}

这是架构(使用&#34; Valuz&#34;替换)

{
    "type": "record",
    "name": "MyClass",
    "namespace": "com.test.avro",
    "fields": [{
        "name": "Meta",
        "type": {
            "type": "record",
            "name": "Meta",
            "fields": [{
                "name": "Type",
                "type": "long"
            },
            {
                "name": "Key",
                "type": "string"
            },
            {
                "name": "Valuz",     <================ This is the "Value" with the typo substitution working fine
                "type": {
                    "type": "record",
                    "name": "Valuz",     <================ This is the "Value" with the typo substitution working fine
                    "fields": [{
                        "name": "ElementType",
                        "type": {
                            "type": "record",
                            "name": "ElementType",
                            "fields": [{
                                "name": "Type",
                                "type": "long"
                            },
                            {
                                "name": "Key",
                                "type": "string"
                            },
                            {
                                "name": "Value",
                                "type": "string"
                            }]
                        }
                    },
                    {
                        "name": "Attributes",
                        "type": {
                            "type": "record",
                            "name": "Attributes",
                            "fields": [{
                                "name": "Type",
                                "type": "long"
                            },
                            {
                                "name": "Key",
                                "type": "string"
                            },
                            {
                                "name": "Value",
                                "type": {
                                    "type": "array",
                                    "items": {
                                        "type": "record",
                                        "name": "Value",
                                        "fields": [{
                                            "name": "Type",
                                            "type": "long"
                                        },
                                        {
                                            "name": "Key",
                                            "type": "string"
                                        },
                                        {
                                            "name": "Value",
                                            "type": "string"
                                        }]
                                    }
                                }
                            },
                            {
                                "name": "ContentType",
                                "type": "long"
                            }]
                        }
                    }]
                }
            }]
        }
    }]
}

我的问题很简单,它是什么&#34;价值&#34;在这种情况下导致Avro架构失败? 根据下面的错误,它说它无法重新定义&#34;价值&#34;,但它首先被定义在哪里?

作为参考,我在Apache NiFi中尝试了这个,它只是说它无法解析模式。我发现此网站Avro schema to JSON Schema引用了此错误,这似乎可以让您更深入地了解该问题:

[ {
  "level" : "fatal",
  "message" : "illegal Avro schema",
  "exceptionClass" : "org.apache.avro.SchemaParseException",
  "exceptionMessage" : "Can't redefine: com.test.avro.Value",
  "info" : "other messages follow (if any)"
} ]

0 个答案:

没有答案