You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Doug Cutting (JIRA)" <ji...@apache.org> on 2012/10/29 20:20:12 UTC

[jira] [Commented] (AVRO-1183) Avro Pair fails to initialize when either they key or value is a list.

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

Doug Cutting commented on AVRO-1183:
------------------------------------

This used to yield a schema like:
{code}
{
  "type" : "record",
  "name" : "Pair",
  "namespace" : "org.apache.avro.mapred",
  "fields" : [ {
    "name" : "key",
    "type" : "int",
  }, {
    "name" : "value",
    "type" : {
      "type" : "record",
      "name" : "ArrayList",
      "namespace" : "java.util",
      "fields" : [ ]
    },
    "order" : "ignore"
  } ]
}
{code}

Such a schema will not correctly write values, since the ArrayList record has no fields.  This is a limitation of Java reflection: one cannot find the element type of an ArrayList at runtime.  So to create a schema for a Pair you'd need to do something like:

{code}
Schema keySchema = Schema.create(Type.INT);
Schema valueSchema = Schema.createArray(Schema.create(Type.INT));
new Pair(key, keySchema, value, valueSchema);
{code}
                
> Avro Pair fails to initialize when either they key or value is a list.
> ----------------------------------------------------------------------
>
>                 Key: AVRO-1183
>                 URL: https://issues.apache.org/jira/browse/AVRO-1183
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.2
>            Reporter: Jeffrey Theobald
>            Priority: Minor
>
> Hello,
> It seems that a change somewhere between 1.5.7 and 1.7.2 (maybe AVRO-966 ?) has broken the Avro Pair object, so that you can no longer instantiate a pair when either the key or the value is a list.
> To replicate this bug, try the following:
> {code}
> Integer key = new Integer(0);
> List<Integer> list = new ArrayList<Integer>();
> Pair<Integer, List<Integer>> pair = new Pair<Integer, List<Integer>>(key, list);
> {code}
> It will produce something like the following exception:
> {noformat}org.apache.avro.AvroRuntimeException: Can't find element type of Collection
> 	at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:281)
> 	at org.apache.avro.specific.SpecificData.getSchema(SpecificData.java:151)
> 	at org.apache.avro.mapred.Pair.<init>(Pair.java:312)
>         .....SNIP.....
> {noformat}
> I've used Integer here for illustration but it also affects SpecificRecord objects.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira