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

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

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.6
    • Fix Version/s: 1.7.7
    • Component/s: java
    • Labels:
      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
          8 kB
          Doug Cutting
        2. AVRO-1449.patch
          10 kB
          Tom White

          Activity

            People

            • Assignee:
              cutting Doug Cutting
              Reporter:
              tomwhite Tom White
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: