You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Skraba (JIRA)" <ji...@apache.org> on 2019/07/04 14:02:00 UTC

[jira] [Commented] (AVRO-2462) Specific record hashCode() with union including "java-class" throws exception

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

Ryan Skraba commented on AVRO-2462:
-----------------------------------

There was some recent and related work on `resolveUnion` for logical types: [https://github.com/apache/avro/pull/329] (AVRO-1891, AVRO-2065).  I'm interested and taking a look.

For info, we use "Stringable" Dates a lot with Avro 1.7.7 (pre-LogicalType), where we encountered this bug.

 

> Specific record hashCode() with union including "java-class" throws exception
> -----------------------------------------------------------------------------
>
>                 Key: AVRO-2462
>                 URL: https://issues.apache.org/jira/browse/AVRO-2462
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.7, 1.9.0
>            Reporter: Ryan Skraba
>            Priority: Major
>             Fix For: 1.9.1
>
>
> Given a specific record generated from the following avsc:
> {code:java}
> {
>   "type": "record",
>   "name": "Lifetime",
>   "fields": [
>     {"name": "name", "type": "string"},
>     {"name": "birth",
>      "type": {"type": "string", "java-class": "java.util.Date"}},
>     {"name": "death",
>      "type": ["null", 
>               {"type": "string", "java-class": "java.util.Date"}],
>       "default": null
>     }
>   ]
> }{code}
> birth is a required field and death is a nullable field.
> The following code works (death is null):
> {code:java}
> Lifetime ws = Lifetime.newBuilder().setName("William Shakespeare")
>     .setBirth(new Date(-12801286800000L)).build();
> long x = ws.hashCode();{code}
> Setting the death field is broken:
> {code:java}
> ws.setDeath(new Date(-11161414800000L));
> long y = ws.hashCode();{code}
> The following exception is thrown:
> {code:java}
> org.apache.avro.AvroRuntimeException: Unknown datum type java.util.Date: Sat Apr 23 00:00:00 CET 1616
> at org.apache.avro.generic.GenericData.getSchemaName(GenericData.java:887)
> at org.apache.avro.specific.SpecificData.getSchemaName(SpecificData.java:420)
> at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:850)
> at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1059)
> at org.apache.avro.generic.GenericData.hashCodeAdd(GenericData.java:1073)
> at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1049)
> at org.apache.avro.specific.SpecificRecordBase.hashCode(SpecificRecordBase.java:84){code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)