[
https://issues.apache.org/jira/browse/AVRO-667?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12910321#action_12910321
]
Scott Carey commented on AVRO-667:
----------------------------------
If you are concerned about performance, then consider changing:
{code}
case STRING:
Utf8 u1 = o1 instanceof Utf8 ? (Utf8)o1 : new Utf8(o1.toString());
Utf8 u2 = o2 instanceof Utf8 ? (Utf8)o2 : new Utf8(o2.toString());
return u1.compareTo(u2);
{code}
to use
getClass().equals()
rather than
instanceof
since instanceof is slower (though not dramatically).
This has limitations for anyone who extends Utf8, but it might be best to mark
it final anyway. Even if it is not final, we can't rely on a subclass
implementing .equals() properly, it might be overridden and break equals()
symmetry. So I think Utf8.class.equals() or Utf8.class == are the right
things to use, possibly while making Utf8 final.
{code}
case STRING:
Utf8 u1 = Utf8.class.equals(o1.getClass()) ? (Utf8)o1 : new
Utf8(o1.toString());
Utf8 u2 = Utf8.class.equals(o2.getClass()) ? (Utf8)o2 : new
Utf8(o2.toString());
return u1.compareTo(u2);
{code}
> GenericArray fails to compare with List. SpecificRecord compare gets
> ClassCastException
> ----------------------------------------------------------------------------------------
>
> Key: AVRO-667
> URL: https://issues.apache.org/jira/browse/AVRO-667
> Project: Avro
> Issue Type: Bug
> Affects Versions: 1.4.0
> Reporter: Scott Carey
> Assignee: Scott Carey
> Priority: Blocker
> Fix For: 1.4.1
>
> Attachments: AVRO-667.patch, AVRO-667.patch, AVRO-667.patch,
> AVRO-667.patch
>
>
> AVRO-637 is incomplete.
> I am unable to convert my SpecificRecord project to 1.4. It compiles, but
> unit tests get runtime exceptions.
> compareTo in GenericData does not handle List vs GenericArray and I get class
> cast exceptions.
> {noformat}
> java.lang.ClassCastException: java.util.ArrayList cannot be cast to
> org.apache.avro.generic.GenericArray
> at org.apache.avro.generic.GenericData.compare(GenericData.java:502)
> at org.apache.avro.specific.SpecificData.compare(SpecificData.java:190)
> at org.apache.avro.generic.GenericData.compare(GenericData.java:494)
> at org.apache.avro.specific.SpecificData.compare(SpecificData.java:190)
> at
> org.apache.avro.specific.SpecificRecordBase.compareTo(SpecificRecordBase.java:45)
> at
> org.apache.avro.specific.SpecificRecordBase.equals(SpecificRecordBase.java:35)
> at com.rr.eventdata.ViewRecord.equals(ViewRecord.java:350)
> at com.rr.eventdata.WriteStuffTest.main(WriteStuffTest.java:143)
> at
> com.rr.eventdata.WriteStuffTest.testReadWriteDataFile(WriteStuffTest.java:55)
> {noformat}
> Also, an array of string in SpecificRecord ends up as List<CharSequence>.
> However, it should be List<? extends CharSequence> or else you can't assign a
> List<String> to it.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.