avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vyacheslav Zholudev (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-966) Bug in GenericData#resolveUnion when resolving union of null and array
Date Wed, 07 Dec 2011 20:40:40 GMT

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

Vyacheslav Zholudev commented on AVRO-966:
------------------------------------------

Sounds convincing. Thanks for the patch!
                
> Bug in GenericData#resolveUnion when resolving union of null and array
> ----------------------------------------------------------------------
>
>                 Key: AVRO-966
>                 URL: https://issues.apache.org/jira/browse/AVRO-966
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.6.1
>            Reporter: Vyacheslav Zholudev
>            Assignee: Doug Cutting
>             Fix For: 1.6.2
>
>         Attachments: AVRO-966-2.patch, AVRO-966.patch, AVRO-966.patch
>
>
> I have a simple avro schema from which I generate an avro specific object:
> {{
> {"type": "record",
>   "name": "org.company.Test",
>   "fields": [
>     { "name": "arr","type": ["null", {"type": "array","items": "float" }], "default":
null }
>   ]
> }
> }}
> Then a simple piece of code to reproduce a bug:
> {{
>   Test test = new Test();
>   List<Float> list = new ArrayList<Float>();
>   list.add(1.1f);
>   list.add(2.2f);
>   test.setArr(list);
>   
>   DataFileWriter<Test> myWriter = new DataFileWriter<Test>(new ReflectDatumWriter(test.getSchema()));
>   File f = new File("/tmp/test.avro");
>   myWriter.create(test.getSchema(), f);
>   myWriter.append(test);
>   myWriter.close();
> }}
> I get an exception:
> {{
> Exception in thread "main" org.apache.avro.file.DataFileWriter$AppendWriteException:
org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"array","items":"float"}]:
[1.1, 2.2]
> 	at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:261)
>         <my code>
> Caused by: org.apache.avro.UnresolvedUnionException: Not in union ["null",{"type":"array","items":"float"}]:
[1.1, 2.2]
> 	at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:549)
> 	at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:137)
> 	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:70)
> 	at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:102)
> 	at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:105)
> 	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:65)
> 	at org.apache.avro.reflect.ReflectDatumWriter.write(ReflectDatumWriter.java:102)
> 	at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:57)
> 	at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:255)
> }}
> My investigation showed that in {{GenericData#resolveUnion}} method {{getSchemaName()}}
is called. And the latter method when checks whether {{datum}} is a record, succeeds. Why
it happens boils down to the fact that in {{ReflectData#createSchema}} an "if"-body under
case {{(type instanceof ParameterizedType)}} is not executed.
> I can supply more details if needed. Or explain in a clear way if I didn't manage to.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message