avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Cutting (JIRA)" <j...@apache.org>
Subject [jira] Updated: (AVRO-361) Specific Compiler fails to handle union with two fixed branches
Date Thu, 21 Jan 2010 23:12:54 GMT

     [ https://issues.apache.org/jira/browse/AVRO-361?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Doug Cutting updated AVRO-361:
------------------------------

             Priority: Blocker  (was: Major)
    Affects Version/s:     (was: 1.3.0)

This looks like the right fix, although we should combine these into a single block in the
switch.


> Specific Compiler fails to handle union with two fixed branches
> ---------------------------------------------------------------
>
>                 Key: AVRO-361
>                 URL: https://issues.apache.org/jira/browse/AVRO-361
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>            Reporter: Scott Carey
>            Priority: Blocker
>             Fix For: 1.3.0
>
>         Attachments: AVRO-361.patch
>
>
> The following record fails to compile with the specific compiler:
> {code}
> {"name": "ipAddr", "type": "record", "fields":[
>   {"name": "addr", "type": [
>     {"name": "IPv6", "type": "fixed", "size": 16 },
>     {"name": "IPv4", "type": "fixed", "size": 4 }]
>   }
>  ]
> }   
> {code}
> The stack trace is:
> {noformat}
> org.apache.avro.AvroRuntimeException: Ambiguous union: [{"type":"fixed","name":"IPv6","size":16},{"type":"fixed","name":"IPv4","size":4}]
> 	at org.apache.avro.Schema$UnionSchema.<init>(Schema.java:613)
> 	at org.apache.avro.Schema.parse(Schema.java:874)
> 	at org.apache.avro.Schema.parse(Schema.java:825)
> 	at org.apache.avro.Schema.parse(Schema.java:709)
> 	at org.apache.avro.specific.SpecificCompiler.compileSchema(SpecificCompiler.java:111)\
> {noformat}
> This is on trunk:
> $ svn info
> Path: .
> URL: http://svn.apache.org/repos/asf/hadoop/avro/trunk/lang/java
> Repository Root: http://svn.apache.org/repos/asf
> Repository UUID: 13f79535-47bb-0310-9956-ffa450edef68
> Revision: 901469
> The code for UnionSchema in Schema.java has this constructor: 
> {code}
> public UnionSchema(List<Schema> types) {
>       super(Type.UNION);
>       this.types = types;
>       int seen = 0;
>       for (Schema type : types) {                 // check legality of union
>         switch (type.getType()) {
>         case UNION: 
>           throw new AvroRuntimeException("Nested union: "+this);
>         case RECORD:
>           if (type.getName() != null)
>             continue;
>         default:
>           int mask = 1 << type.getType().ordinal();
>           if ((seen & mask) != 0)
>             throw new AvroRuntimeException("Ambiguous union: "+this);
>           seen |= mask;
>         }
>       }
>     }
> {code}
> That allows only one member of any type other than RECORD.  The spec says:
> {quote}
> Unions may not contain more than one schema with the same
> type, except for the named types record, fixed and enum.
> {quote}
> The code above does not adhere to this.
> I am attaching a patch for only this code, but a unit test with a test schema that has
two records, two fixed, and two enum in it as well as one of each of the unnamed types is
probably necessary as well.  I am not yet familiar with the test infrastructure.
> I am also not familiar with what else this may impact.

-- 
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