Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.6.1
-
None
-
None
Description
Suppose that you define two different avro objects:
{"name":"A", "namespace":"com.something", "type":"record", ...} {"name":"B", "namespace":"com.anotherthing", "type":"record", ...}Then define a union of the two:
{"name":"bothAAndB", "type":[
{"name":"A", "namespace":"com.something", "type":"record", ...},
{"name":"B", "namespace":"com.anotherthing", "type":"record", ...}]}
If you write an object of type A or B into a GenericRecord and try to use org.apache.avro.generic.GenericDatumWriter to store the object, you will get an org.apache.avro.UnresolvedUnionException exception.
Very specifically, it looks like org.apache.avro.UnionSchema.getIndexNamed is being called by org.apache.avro.generic.GenericDatumWriter.resolveUnion with the short name of the record, but that the org.apache.avro.UnionSchema object contains the full names of the objects. So, org.apache.avro.UnionSchema.getIndexNamed doesn't find a match and Avro fails to find an object in the union that matches the object in the datum.
So... I'd like to see one of two fixes: (1) an informative error message telling me that I can't form a union of records from different namespaces, or (2) a successful lookup of the schema and record writing.