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.
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
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With