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

Report specific location of incompatibility in record schema

    XMLWordPrintableJSON

Details

    Description

      Given a reader schema for a record with a field having a mandatory value:

      {
        "type" : "record",
        "name" : "Account",
        "fields" : [ {
          "name" : "age",
          "type" : "int"
        } ]
      }
      

      and a writer schema for a record with a field having a nullable value:

       {
        "type" : "record",
        "name" : "Account",
        "fields" : [ {
          "name" : "age",
          "type" : [ "null", "int" ],
          "default" : null
        } ]
      } 
      

      invoking SchemaCompatibility.checkReaderWriterCompatibility(readerSchema, writerSchema) finds an incompatibility with message:

      reader type: INT not compatible with writer type: NULL

      and location:

      /

      However, I want it to instead tell me the specific location of the incompatibility in the record schema:

      /fields/0/type/0
      

      This failing unit test demonstrates the bug:

      class SchemaCompatibilityTest {
      
        @Test
        void given_incompatibility_in_record_schema_then_found_incompatibility_location() {
          var mandatorySchema = SchemaBuilder.record("Account").fields()
              .name("age").type().intType().noDefault()
              .endRecord();
          var optionalSchema = SchemaBuilder.record("Account").fields()
              .optionalInt("age")
              .endRecord();
      
          var compatibility = SchemaCompatibility.checkReaderWriterCompatibility(
              mandatorySchema, optionalSchema);
      
          assertThat(compatibility.getType()).isEqualTo(SchemaCompatibilityType.INCOMPATIBLE);
      
          var incompatibility = compatibility.getResult().getIncompatibilities().get(0);
          assertThat(incompatibility.getMessage()).isEqualTo("reader type: INT not compatible with writer type: NULL");
          assertThat(incompatibility.getLocation()).isEqualTo("/fields/0/type/0");
        }
      }
      

      Attachments

        1. AVRO-3612.patch
          0.8 kB
          Chin Huang

        Issue Links

          Activity

            People

              Unassigned Unassigned
              pukkaone Chin Huang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m