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/29 09:47:00 UTC
[jira] [Created] (AVRO-2488) GenericData.validate(...) has
inconsistent behaviour with unknown datum
Ryan Skraba created AVRO-2488:
---------------------------------
Summary: GenericData.validate(...) has inconsistent behaviour with unknown datum
Key: AVRO-2488
URL: https://issues.apache.org/jira/browse/AVRO-2488
Project: Apache Avro
Issue Type: Bug
Components: java
Reporter: Ryan Skraba
I noticed this when working with AVRO-2642. An unknown datum validates differently whether its in a UNION or not.
When using the schema from that JIRA with a GenericRecord:
{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}
The following code validates as false:
{code:java}
GenericRecord r = new GenericData.Record(theAboveSchema);
r.put("name", "William Shakespeare");
r.put("birth", new Date(-12801286800000L));
boolean isValid = GenericData.get().validate(r.getSchema(), r); // false
{code}
Fair enough – a specific record with that schema is valid, but **java-class** is a SpecificData concept that is unknown to GenericData.
The following code, however throws an exception:
{code:java}
GenericRecord r = new GenericData.Record(theAboveSchema);
r.put("name", "William Shakespeare");
r.put("birth", new Date(-12801286800000L));
r.put("death", new Date(-11161414800000L));
boolean isValid = GenericData.get().validate(r.getSchema(), r);
// AvroRuntimeException: Unknown datum type java.util.Date
{code}
I would expect the two records to either be equally false (preferred) or to both throw an unknown datum type.
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)