这个问题/答案(How to nest records in an Avro schema?)清除了如何嵌套复杂类型(在这种情况下为记录)。但是,我想知道是否有人知道如何为记录类型设置默认值。我在上面问题中显示的示例中遇到错误,地址丢失了,我更喜欢avro将其默认为空字典或至少是空字符串 - 而不是我必须默认它提前。
答案 0 :(得分:2)
您只能将空值作为AVRO中嵌套对象的默认值。这就是具有默认空值
的模式{
"name": "person",
"type": "record",
"fields": [
{"name": "firstname", "type": "string"},
{"name": "lastname", "type": "string"},
{
"name": "address",
"type": ["null" , {
"type" : "record",
"name" : "AddressUSRecord",
"fields" : [
{"name": "streetaddress", "type": "string"},
{"name": "city", "type": "string"}
]
}],
"default": null
}
]
}