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

Generated Avro schema from Thrift is missing default values

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.8.2, 1.9.2
    • None
    • java
    • None

    Description

      Hi,

      Currently, using the thrift class to generate Avro's schema, there is missing default values.

      In our project, the business data will be transmitted through the Thrift framework and saved in the avro file, and then use GenericRecord to perform business delivery on various other business platforms, but use this schema for data deserialization, there is no default value for the field, resulting in Troublesome work.

      Thrift's IDL:

      namespace java org.apache.avro.thrift.test
      struct SimpleDefault{
      
      1: i16 im_default = 6;
      
      2: required i16 im_required = 6;
      
      3: optional i16 im_optional = 6;
      
      }
      
      

      Generated Schema for using ThriftData:

      {
        "type":"record",
        "name":"SimpleDefault",
        "namespace":"org.apache.avro.thrift.test",
        "fields":[{
          "name":"im_default",
          "type":{
            "type":"int",
            "thrift":"short"
          }
        },{
          "name":"im_required",
          "type":{
            "type":"int",
            "thrift":"short"
          }
      },{
          "name":"im_optional",
          "type":["null",{
            "type":"int",
            "thrift":"short"
          }]
      }]
      }
       

      Default value is missing.

      Deserialization (GenericDatumReader):

      
      {
      
        "im_default":6,
      
        "im_required":6,
      
        "im_optional":null
      
      }
      
      

      I am trying to add a default value in ThriftData because I found that it is not set.
      https://github.com/apache/avro/blob/9af218d3c060da103868cdc69d7b39fc8d50dcbc/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java#L197

      Attachments

        Activity

          People

            Unassigned Unassigned
            zeshuai007 Zezeng Wang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: