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

Union: validating default values

    XMLWordPrintableJSON

    Details

    • Type: Wish
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: spec
    • Labels:
      None

      Description

      Hi guys,

      I'm trying to set the default value for a field (using Java) and I've got a nasty exception:

      Exception in thread "main" org.apache.avro.AvroTypeException: Invalid default for field first: "Andy" not a ["null","string"]
      
          at org.apache.avro.Schema.validateDefault(Schema.java:1542)
      ...

      In the documentation of Apache Avro: Unions

      Unions, as mentioned above, are represented using JSON arrays. For example, ["null", "string"] declares a schema which may be either a null or string.
      
      (Note that when a default value is specified for a record field whose type is a union, the type of the default value must match the first element of the union. Thus, for unions containing "null", the "null" is usually listed first, since the default value of such unions is typically null.)
      

      Would you please tell me why the type of the default value must match the first element of the union? Is it better if the value match any element?

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              anhldbk Andy Le
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: