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

Himanshu Mishra commented on AVRO-966:
--------------------------------------

It fails in case of a "map" too
                
> 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

        

Reply via email to