According to this question on nesting Avro schemas, the right way to nest a record schema is as follows:
{
"name": "person",
"type": "record",
"fields": [
{"name": "firstname", "type": "string"},
{"name": "lastname", "type": "string"},
{
"name": "address",
"type": {
"type" : "record",
"name" : "AddressUSRecord",
"fields" : [
{"name": "streetaddress", "type": "string"},
{"name": "city", "type": "string"}
]
},
}
]
}
I don't like giving the field the name address
and having to give a different name (AddressUSRecord
) to the field's schema. Can I give the field and schema the same name, address
?
What if I want to use the AddressUSRecord
schema in multiple other schemas, not just person
? If I want to use AddressUSRecord
in another schema, let's say business
, do I have to name it something else?
Ideally, I'd like to define AddressUSRecord
in a separate schema, then let the type of address
reference AddressUSRecord
. However, it's not clear that Avro 1.8.1 supports this out-of-the-box. This 2014 article shows that sub-schemas need to be handled with custom code. What the best way to define reusable schemas in Avro 1.8.1?
Note: I'd like a solution that works with Confluent Inc.'s Schema Registry. There's a Google Groups thread that seems to suggest that Schema Registry does not play nice with schema references.