Avro 模式中嵌套记录的默认值

Defaults for nested records in an Avro schema

此 question/answer (How to nest records in an Avro schema?) 阐明了如何嵌套复杂类型(在本例中为记录)。但是,我想知道是否有人知道如何为记录类型设置默认值。在上述问题中显示的示例中,我收到错误,地址丢失,我更希望 avro 将其默认为空字典或至少为空字符串 - 而不是我必须将其默认为提前。

您只能将 null 值作为 AVRO 中嵌套对象的默认值。这是具有默认 null

的架构的样子
{
    "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
        }
    ]
}