avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Massie (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (AVRO-18) add enum type
Date Fri, 24 Apr 2009 22:21:30 GMT

    [ https://issues.apache.org/jira/browse/AVRO-18?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12702580#action_12702580
] 

Matt Massie edited comment on AVRO-18 at 4/24/09 3:20 PM:
----------------------------------------------------------

I'd like to suggest that we use this enum with union in order support discriminant unions
much like xdr.

For example, in XDR, the syntax for a union is..

{code}
enum my_enum {
  FOO,
  BAR,
  BAZ
};

union my_union switch (my_enum id){
   case FOO:
      string foo<>;
   case BAR:
      double bar;
   case BAZ:
      short baz;
   default:
      void
}
{code}

Those enums are important in order to know the type of object being (de)serialized in the
union.  

Looking at the "interop.js" file in the current Avro distro, I see the union field looks like

{code}
"unionField": ["boolean", "double", {"type":"array","items": "bytes"}],
{code}

which as far as I can tell, means that the union field can be a boolean, double or array.
 How can you discriminate one from the other without a discriminant?

Maybe we  need something like the following...

{code}
{"name": "Foo", "type": "enum", "values": ["a", "b", "c"]}

{"type": "union", "name": "my_union", "discriminant": "Foo",
  "schemas": {
     "a": "boolean",
     "b": "double",
     "c": {"type": "array", "items": "bytes"}
  }.
  "default": "void"
}
{code}

... or something similar?


      

  



      was (Author: massie):
    I'd like to suggest that we use this enum with union in order support discriminant unions
much like xdr.

For example, in XDR, the syntax for a union is..

{code}
enum my_enum {
  FOO,
  BAR,
  BAZ
};

union my_union switch (my_enum id){
   case FOO:
      string foo<>;
   case BAR:
      double bar;
   case BAZ:
      short baz;
   default:
      void
}
{code}

Those enums are important in order to know the type of object being (de)serialized in the
union.  

Looking at the "interop.js" file in the current Avro distro, I see the union field looks like

<code>
"unionField": ["boolean", "double", {"type":"array","items": "bytes"}],
</code>

which as far as I can tell, means that the union field can be a boolean, double or array.
 How can you discriminate one from the other without a discriminant?

Maybe we  need something like the following...

<code>
{"name": "Foo", "type": "enum", "values": ["a", "b", "c"]}

{"type": "union", "name": "my_union", "discriminant": "Foo",
  "schemas": {
     "a": "boolean",
     "b": "double",
     "c": {"type": "array", "items": "bytes"}
  }.
  "default": "void"
}
</code>

... or something similar?


      

  


  
> add enum type
> -------------
>
>                 Key: AVRO-18
>                 URL: https://issues.apache.org/jira/browse/AVRO-18
>             Project: Avro
>          Issue Type: New Feature
>          Components: spec
>            Reporter: Doug Cutting
>
> Avro schemas should support enum types.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message