Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defaults for nested records in an Avro schema

Tags:

avro

This question/answer (How to nest records in an Avro schema?) clears things up on how to nest complex types (records in this case). However, I'm wondering if anyone knows how to have default values for record types. I'm getting errors when in the example shown in the above question, the address is missing and I'd prefer avro to default it to an empty dictionary or at the very least to an empty String - instead of me having to default it in advance.

like image 254
Sokratis Avatar asked Oct 21 '25 05:10

Sokratis


1 Answers

You can only have null value as default value for nested objects in AVRO. This is how looks like the schema with default null value

{
    "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
        }
    ]
}
like image 93
hlagos Avatar answered Oct 26 '25 16:10

hlagos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!