Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
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:
{ "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 } ] }
The following code validates as false:
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
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:
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
I would expect the two records to either be equally false (preferred) or to both throw an unknown datum type.
Attachments
Issue Links
- is related to
-
AVRO-2462 Specific record hashCode() with custom stringable java-class throws exception
- Open