Avro
  1. Avro
  2. AVRO-1449

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

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major 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.

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

        Activity

        No work has yet been logged on this issue.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development