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

Check default value's type matches union at schema parse time

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.6
    • 1.7.7
    • java
    • None

    Description

      A common Avro mistake is to declare optional fields as follows:

      "type": ["string", "null"], "default": null
      

      This fails at runtime since the default value's type (null) doesn't match the type of the first type in the union (string). The correct declaration is:

      "type": ["null", "string"], "default": null
      

      Doug suggested that we throw an exception at schema parse time for cases like this. To ensure backwards compatibility we could make it optional; tools could emit a warning.

      Attachments

        1. AVRO-1449.patch
          10 kB
          Thomas White
        2. AVRO-1449.patch
          8 kB
          Doug Cutting

        Activity

          People

            cutting Doug Cutting
            tomwhite Thomas White
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: