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

Avro default values not working

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.8.1
    • Fix Version/s: None
    • Component/s: java
    • Labels:
      None

      Description

      We have a field in avro schema like this:

      { "name" : "id", "type" : "int", "default": 0 }

       The expected behavior is that when the field is not supplied, it should have the defauly value of 0.

      But we get an exception when we do not provide the value:

      java.lang.NullPointerException: null of int in field id 
      at org.apache.avro.generic.GenericDatumWriter.npe(GenericDatumWriter.java:132)
      at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:126)
      at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
      at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:60)
      at com.walmart.wfm.parser.AvroEncode.avroEncode(AvroEncode.java:127)
      at com.walmart.wfm.parser.AvroEncode.main(AvroEncode.java:36)
      Caused by: java.lang.NullPointerException
      at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:117)
      at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
      at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:153)
      at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:143)
      at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:105)
      at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
      at org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:179)
      at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:107)
      at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
      at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:153)
      at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:143)
      at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:105)
      at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
      at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:153)
      at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:143)
      at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:105)
      ... 4 more

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              vidhigavadia Vidhi Gavadia
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: