I defined an Avro schema consisting of a record that contains a union of two (or more) different records, such as:
{ "type":"record", "name":"MyCompositeRecord", "fields": [ {"name":"SomeCommonData","type":"string"}, {"name":"MoreCommonData","type":"float"}, {"name":"CompositeRecord","type": [ { "type":"record", "name":"FirstOption", "fields": [ {"name":"x","type":"string"}, {"name":"y","type":"long"} ] }, { "type":"record", "name":"SecondOption", "fields": [ {"name":"z","type":"int"}, {"name":"w","type":"float"}, {"name":"m","type":"double"}, {"name":"l","type":"boolean"} ] } ] } ] }
It doesnβt look very clear, but I hope you understand: I have a record consisting of some data ("SomeCommonData" and "MoreCommonData") and a combination of two different types of records ("FirstOption" and "FirstOption", SecondOption ") At the time of serialization / deserialization, I should be able to create one of two subrecords and serialize "MyCompositeRecord".
I have not tried to generate code for the circuit, since I plan to use only general records. However, I am not sure what and how such shared records can be serialized. I can not find a single example on the Internet. I am going to use java for serialization / deserialization. I was able to create a reader script for the circuit as follows:
Schema.Parser parser = new Schema.Parser(); Schema schema = parser.parse(COMPOSITE_SCHEMA); DatumWriter<GenericRecord> writer = new GenericDatumWriter<>(schema); DatumReader<GenericRecord> reader = new GenericDatumReader<>(schema); GenericRecord datum = new GenericData.Record(schema);
Any ideas on how to proceed from here to actually create a record?
thanks