Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-2488

GenericData.validate(...) has inconsistent behaviour with unknown datum

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • java
    • 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

          Activity

            People

              Unassigned Unassigned
              rskraba Ryan Skraba
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: