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

Doug Cutting updated AVRO-336:
------------------------------

    Attachment: AVRO-336.patch

It seems you have a GenericArray instance whose schema is not an array schema 
but is a record schema.  When constructing a GenericArray one must pass the 
schema of the array itself, not its element type.

I suspect the fix is, in your code, to pass the appropriate array schema to 
GenericArray's constructor.  Also, in Avro, we should check the type of the 
schema passed to such constructors to make this easier to debug in the future.  
I've attached a patch that does this.

> The specific compiler could also generate equals() methods (which would be 
> more efficient than traversing the schema).

Yes, that could probably be done.


> Equals() on SpecificRecord fails (java)
> ---------------------------------------
>
>                 Key: AVRO-336
>                 URL: https://issues.apache.org/jira/browse/AVRO-336
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.3.0
>            Reporter: Scott Carey
>             Fix For: 1.3.0
>
>         Attachments: AVRO-336.patch
>
>
> rev 899520, trunk.
> Calling equals() on an object generated by the SpecificAPI fails.
> The object is a record with several fields, one is an array.  This object can 
> serialize and deserialize, binary and json.  But equals() fails, as well as 
> hashCode() in some cases.
> It fails in Schema.java, line 217.
> {code}
>   /** If this is an array, returns its element type. */
>   public Schema getElementType() {
>     throw new AvroRuntimeException("Not an array: "+this);
>   }
> {code}
> This looks unimplemented.
> The stack trace is:
> {noformat}
> Exception in thread "main" org.apache.avro.AvroRuntimeException: Not an 
> array: 
> {"type":"record","name":"Variable","namespace":"com.rr.avro","fields":[{"name":"variableId","type":"int"},{"name":"selectedValue","type":"string"}]}
>       at org.apache.avro.Schema.getElementType(Schema.java:217)
>       at org.apache.avro.generic.GenericData.compare(GenericData.java:468)
>       at org.apache.avro.specific.SpecificData.compare(SpecificData.java:250)
>       at org.apache.avro.specific.SpecificData.compare(SpecificData.java:242)
>       at 
> org.apache.avro.specific.SpecificRecordBase.compareTo(SpecificRecordBase.java:45)
>       at 
> org.apache.avro.specific.SpecificRecordBase.equals(SpecificRecordBase.java:35)
> {noformat}
> That record is the element type of the array, so I think this is just due to 
> the implementation being incomplete.
> The specific compiler could also generate equals() methods (which would be 
> more efficient than traversing the schema).  I wonder if eclipse's "generate 
> hashcode and equals" code is usable.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to