[
https://issues.apache.org/jira/browse/AVRO-2462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16895021#comment-16895021
]
Ryan Skraba commented on AVRO-2462:
-----------------------------------
I opened the PR https://github.com/apache/avro/pull/597, but I'm not sure it
should be applied. It fixes one specific (Date) case of using a `java-class`
Avro annotation to generate a specific record, but the same problem would
probably occur for any custom stringable type.
In our case, it looks like Date as a stringable is stable enough as long as we
take a bit of care: (1) when we generate a Date to store in the specific
record, we make sure it's in UTC, and (2) we require all nodes in the cluster
to have the same locale.
I have two questions:
Is it expected that any STRING field with a `java-class` annotation in the
schema be treated as a `@Stringable`? The latter is a ReflectData concept. In
practice, it _mostly_ works like that, but `hashCode` is broken when that field
is in a union.
Is the set of stringable classes for specific data meant to be open for
extension?
> Specific record hashCode() with custom stringable 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
> Assignee: Ryan Skraba
> Priority: Major
> Fix For: 1.9.1
>
> Attachments: AVRO-2462-unit-test.patch
>
>
> 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.14#76016)