I have two types of AvroRecords that both extend avro.SpecificRecord. Is there a way to make one a subclass of the other in Java? One of them is PersonRecord and the one I would like to be its subclass is EmployeeRecord. The reason I don't want to populate normal Java classes with the avro data is that I am using hadoop and would like to work with the avro files directly if it is possible.
To clarify, it is the polymorphism that I am interested in. I would like to be able to use a function that takes as argument a PersonRecord with an EmployeeRecord.
Thanks!
I think I understand what you're trying to do ("subclass" an Avro record in the Avro Schema definition file) but I don't think it's possible.
Instead, a way to do this would be to have EmployeeRecord
have a PersonRecord
member nested within it, and then the Employee-specific related info following. For example :
{
"type": "record",
"name": "PersonRecord",
"namespace": "com.yourapp",
"fields": [
{
"name": "first",
"type": "string"
},
{ etc... }
]
}
{
"type": "record",
"name": "EmployeeRecord",
"namespace": "com.yourapp",
"fields": [
{
"name": "PersonInfo",
"type": "PersonRecord"
},
{
"name": "salary",
"type": "int"
},
{ etc... }
]
}
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