如何为复杂的json文档定义avro模式?

eagi6jfj  于 2021-06-08  发布在  Kafka
关注(0)|答案(1)|浏览(382)

这是我的json的一个例子:

{"ID":2,"name":"Donatello","lastname":"Di Niccoló","age":23,"hobbies":["reading","dancing",{"sports":["rafting","baseball"]}],"address":{"street":"Tepito", "number":"77", "districts":"Benito Juárez", "country": "CDMX"}}

这是我的avro模式

{"type":"record","name":"myrecord","fields":[ 
{"name":"ID","type":"int"}, 
{"name":"name", "type": "string"},
{"name":"lastname", "type": "string"},
{"name":"age", "type": "int"},
{"name":"hobbies","type": {
        "type": "array",
        "items": {
        "type": "array", "items": "string",
        "type":"record","name":"myhobbies",
        "fields":[
                    {"name":"sports","type":{"type": "array", "items": "string"}}
                ]
}       }
},
{"name":"address","type":{"type":"record","name":"myaddress",
    "fields":[
    {"name":"street","type":"string"},
    {"name":"number","type":"string"},
    {"name":"districts","type":"string"},
    {"name":"country","type":"string"}
    ]

}
}
]}

我需要的avro格式,因为我想开始一个制作人与Kafka,但当我开始它,有一个错误,当我进入前一个记录。因为avro架构与记录不匹配。如何使他们匹配

Yeah Nitin Tripathi

{"type":"record","name":"myrecord","fields":[ 
{"name":"ID","type":"int"}, 
{"name":"name", "type": "string"},
{"name":"lastname", "type": "string"},
{"name":"age", "type": "int"},
{"name":"hobbies","type": {
        "type": "array",
        "items": {
        "type":"record","name":"myhobbies",
        "fields":[
                    {"name":"sports","type":{"type": "array", "items": "string"}}
                ]
}       }
},
{"name":"address","type":{"type":"record","name":"myaddress",
    "fields":[
    {"name":"street","type":"string"},
    {"name":"number","type":"string"},
    {"name":"districts","type":"string"},
    {"name":"country","type":"string"}
    ]

}
}
]}

我试过了,但没用

xggvc2p6

xggvc2p61#

数组使用类型名“array”并支持单个属性,但是,嗜好的模式混合了string和myhabbies类型

相关问题