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

enable validation of default values in schemas by default

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.8.1
    • 1.9.0
    • java
    • None
    • Incompatible change

    Description

      suppose i have the following schema evolution:

      {
        "name": "Bob",
        "type": "record",
        "fields": [
          {"name": "f1", "type": "int"}
        ]
      }
      

      and then:

      {
        "name": "Bob",
        "type": "record",
        "fields": [
          {"name": "f1", "type": "int"},
          {"name": "f2", "type": "boolean", "default": "true"}
        ]
      }
      

      the default value for "f2" is specified as the STRING "true" (and not the literal boolean true).

      if this default value is ever accessed (when reading a gen1-serialized object as a gen2) we get this:

      org.apache.avro.AvroTypeException: Non-boolean default for boolean: "true"
      
      	at org.apache.avro.io.parsing.ResolvingGrammarGenerator.encode(ResolvingGrammarGenerator.java:408)
      	at org.apache.avro.io.parsing.ResolvingGrammarGenerator.getBinary(ResolvingGrammarGenerator.java:307)
      	at org.apache.avro.io.parsing.ResolvingGrammarGenerator.resolveRecords(ResolvingGrammarGenerator.java:285)
      	at org.apache.avro.io.parsing.ResolvingGrammarGenerator.generate(ResolvingGrammarGenerator.java:118)
      	at org.apache.avro.io.parsing.ResolvingGrammarGenerator.generate(ResolvingGrammarGenerator.java:50)
      	at org.apache.avro.io.ResolvingDecoder.resolve(ResolvingDecoder.java:85)
      	at org.apache.avro.io.ResolvingDecoder.<init>(ResolvingDecoder.java:49)
      	at org.apache.avro.io.DecoderFactory.resolvingDecoder(DecoderFactory.java:307)
      	at org.apache.avro.generic.GenericDatumReader.getResolver(GenericDatumReader.java:127)
      	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:142)
      

      yet Schema.parse() passes for this

      Attachments

        1. AVRO-2035.patch
          1.0 kB
          Doug Cutting

        Issue Links

          Activity

            People

              cutting Doug Cutting
              radai Radai Rosenblatt
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: