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

Validation of Union Schemas

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8.2
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      When validating a union Schema in the method

      Schema.isValidDefault(Schema schema, JsonNode defaultValue)

      for the case of UNION it only validates the first type of the union: 

      case UNION: // union default: first branch
      return isValidDefault(schema.getTypes().get(0), defaultValue);
      

      This leads to some warnings that can create confusion.

      For example, if you have a field like this:

      {
        "name" : "synonym",
        "type" : [ "null", "boolean" ],
        "default" : false
      }
      

      and you assign it false as default you get this warning because it only validates that false is not null:

      [WARNING] Avro: Invalid default for field synonym: false not a ["null","boolean"]

      I think in this cases the validation should check all the types of the union to avoid these warnings.

      I would be happy to create a PR to improve this if you think we should go for it.

       

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              marcoslg Marcos Lopez Gonzalez
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: