Using typed lists in Pangool

7 views
Skip to first unread message

Pere Ferrera

unread,
Dec 31, 2013, 4:44:41 AM12/31/13
to pangoo...@googlegroups.com
Hello,

While Pangool doesn't (yet) support directly using lists in a Tuple Field, one can use Avro very easily to achieve that. Following I will show a simple example how to achieve it.
Let's imagine we want to add a Field "labels" which contains a list of strings to our Schema, we will define it as follows:

fields.add(Fields.createAvroField("labels", labelsAvroSchema, true));

And the variable labelsAvroSchema has been defined as:

org.apache.avro.Schema labelsAvroSchema = org.apache.avro.Schema.createArray(org.apache.avro.Schema.create(org.apache.avro.Schema.Type.STRING));

This single line defines an Avro Schema that is an array of Strings.
Note how we use fully-qualified "Schema" and "Type" from Avro, avoiding collisions with similar Pangool classes.

After this we can safely set a Java list of strings in the Tuple field "labels". A Java array of strings will also be serialized properly.

Pere.


Reply all
Reply to author
Forward
0 new messages