Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclassing Avro record?

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!

like image 889
grasshopper Avatar asked Jan 09 '14 19:01

grasshopper


1 Answers

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... }
    ]
}
like image 168
jtravaglini Avatar answered Sep 23 '22 10:09

jtravaglini