Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Avro, mail # user - AvroIDL and nested records


Copy link to this message
-
Re: AvroIDL and nested records
Doug Cutting 2012-02-03, 20:50
Kevin,

This looks like a reasonable way to define things to me.  If you look at
the Schema in the generated Java code for Actor you'll see that the
other types are nested in that Schema.  Whether things like Joint and
CompleteShape are ever instaniated outside of an Actor is up to your
application.

Hope this helps,

Doug

On 02/02/2012 01:22 PM, Kevin Meinert wrote:
>
> ------------------------------------------------------------------------
> From: Kevin Meinert
> Sent: 2/2/2012 1:58 PM
> To: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> Subject: AvroIDL and nested records
>
>
> How would I nest records in AvroIDL?
>
> Here's my datastructure for "Actor" (see bottom), initially I tried to
> nest records inside of records, but the idl compiler didn't take it.  
> My datafiles will only ever include an "Actor", never the other types,
> i'm concerned about space and dont want extra fields hanging around
> bloating the filesize...
>
> Do I risk having CompeteShape and Joint being instantiated (and taking
> extra space), or is the below correct way to nest records (and use
> custom record types inside arrays).   Would be nice to see this type of
> example in the AvroIDL example online... defining your own types and
> using them nested in other types, as well as inside arrays.
>
> thanks,
>
> /**
>  * Actor protocol
>  */
> @namespace("kevin.foo.bar")
> protocol ActorProto
> {
>    /** definition, do not want instantiated! */
>    enum ShapeType
>    {
>       SQUARE,
>       CIRCLE,
>       POLYGON
>    }
>    /** definition, do not want instantiated! */
>    enum PhysicsType
>    {
>       STATIC,
>       DYNAMIC
>    }
>    /** definition, do not want instantiated! */
>    enum JointType
>    {
>       REVOLUTE
>    }
>
>    /** definition, do not want instantiated! */
>    record CompleteShape
>    {
>       int x;
>       int y;
>       int height;
>       int width;
>       float rotation;
>       PhysicsType type;
>       ShapeType shape;
>       float elasticity;
>       float friction;
>       float mass;
>       array<float> verts;
>    }
>    /** definition, do not want instantiated! */
>    record Joint
>    {
>       int l0;
>       int l1;
>       JointType type;
>    }
>
>    record Actor
>    {
>       int other_misc_data; // todo: fill in more actor fields...
>       array<CompleteShape> body_shapes;
>       array<Joint>         body_joints;
>    }
> }
>
>