【问题标题】:How to define avro schema for complex json document?如何为复杂的 json 文档定义 avro 模式?
【发布时间】:2018-01-02 13:42:35
【问题描述】:

这是我的 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 格式,因为我想创建一个制作人 whit 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"}
    ]

}
}
]}

我试过了,还是不行:(

【问题讨论】:

    标签: json database apache-kafka avro confluent-platform


    【解决方案1】:

    数组使用类型名称“array”并支持单个属性,但是,爱好的模式混合了字符串和 myhobbies 类型

    【讨论】:

      猜你喜欢
      • 2014-08-24
      • 1970-01-01
      • 2021-10-30
      • 2017-01-21
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多