Details

Description

Currently, AvroStorage does not allow recursive records in Avro schema because it is not possible to define Pig schema for recursive records. (i.e. records that have self-referencing fields cause an infinite loop, so they are not supported.)

Even though there is no natural way of handling recursive records in Pig schema, I'd like to propose the following workaround: mapping recursive records to bytearray.

Lastly, we can store these tuples as Avro files by specifying schema. Since we can no longer construct Avro schema from Pig schema, it is required for the user to provide Avro schema via the 'schema' parameter in STORE function.

Update the current generic union check so that it can handle recursive records. Currently, AvroStorage checks if the Avro schema contains 1) recursive records and 2) generic unions, and fails if so. But since I am going to remove the 1st check, the 2nd check should be able to handle recursive records without stack overflow.

Update AvroSchema2Pig so that recursive records can be detected and mapped to bytearrays in Pig schema.

Add the 'no_schema_check' parameter to STORE function so that results can be stored even though there exists discrepancy between Avro schema and Pig schema. Since Avro schema for STORE function cannot be constructed from Pig schema, it has to be specified by the user via the 'schema' parameter, and schema check has to be disabled by 'no_schema_check'.

Update AvroStorage wiki.

Add unit tests.

I do not think that any incompatibility issues will be introduced by this.

P.S. The reason why I chose to map recursive records to bytearray instead of empty tuple is because I cannot refer to any field if I use empty tuple. For example, if Pig schema is defined as follows:

{value: int,next: ()}

I get an exception when I attempt to refer to any field in loaded tuples since their schema is not defined (i.e. empty tuple).

ERROR 1127: Index 0 out of range in schema

This is all what I found by trials and errors, so there might be something that I am missing here. If so, please let me know.

Cheolsoo Park
added a comment - 20/Aug/12 06:35 There was a typo in the code:
- String expected = basedir + "expected_testRecursiveRecordReference1" ;
+ String expected = basedir + "expected_testRecursiveRecordReference1.avro" ;
Uploaded a new patch with the fix. I verified that all the tests pass in both 20 and 23.
Thanks!