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

Schema validator cannot find broken backwards compatibility in Union type elements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 1.8.1
    • 1.9.0, 1.8.2
    • None
    • None

    Description

      Consider below 2 schemas:

      Schema 1:

      [
        {
          "type": "record",
          "name": "rec1",
          "fields": [
            {
              "name": "age",
              "type": "long"
            }
          ]
        },
        {
          "type": "record",
          "name": "rec2",
          "fields": [
            {
              "name": "username",
              "type": "string"
            }
          ]
        }
      ]
      

      Schema 2:

      [
        {
          "type": "record",
          "name": "rec1",
          "fields": [
            {
              "name": "age",
              "type": "long"
            },
            {
              "name": "address",
              "type": "string"
            }
          ]
        },
        {
          "type": "record",
          "name": "rec2",
          "fields": [
            {
              "name": "username",
              "type": "string"
            }
          ]
        }
      ]
      

      The rec1 field in these 2 unions are not compatible, because the address field of rec1 in the second one is not nullable. However, if we check them with validate like below, validator doesn't return any error:

          final SchemaValidator backwardValidator = new SchemaValidatorBuilder().canReadStrategy().validateLatest();
          final Schema schema1 = new Schema.Parser().parse(schema1Str);
          final Schema schema2 = new Schema.Parser().parse(schema2Str);
          backwardValidator.validate(schema2, Arrays.asList(schema1));
      

      Attachments

        1. AVRO-1883.1.patch
          2 kB
          Yibing Shi

        Issue Links

          Activity

            People

              Yibing Yibing Shi
              Yibing Yibing Shi
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: