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

Issue with null default value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Not A Problem
    • 1.8.2
    • None
    • java
    • None
    • Java/IntelliJ/Maven

    • Hide
      {
          "namespace": "fr.mediametrie.internet.pame.meter.avro",
          "type": "record",
          "name": "MobtabAvroHit",
          "fields": [
              {
                  "name": "time_usec",
                  "type": ["null", "string"],
                  "default": null
              },
              {
                  "name": "mobile_event_type",
                  "type": ["null", "string"],
                  "default": null
              },
              {
                  "name": "panelist_info",
                  "type": {
                      "type": "record",
                      "name": "MobtabAvroPanelistInfo",
                      "fields": [
                          {
                              "name": "panel_id",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "panelist_id",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "household_id",
                              "type": ["null", "string"],
                              "default": null
                          }
                      ]
                  }
              },
              {
                  "name": "device_info",
                  "type": {
                      "type": "record",
                      "name": "MobtabAvroDeviceInfo",
                      "fields": [
                          {
                              "name": "model_name",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "operating_system_name",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "operating_system_version",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "type",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "ad_id",
                              "type": ["null", "string"],
                              "default": null
                          }
                      ]
                  }
              },
              {
                  "name": "mobile_web_event",
                  "type": {
                      "type": "record",
                      "name": "MobtabAvroMobileWebEvent",
                      "fields": [
                          {
                              "name": "url",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "user_agent",
                              "type": ["null", "string"],
                              "default": null
                          }
                      ]
                  }
              },
              {
                  "name": "mobile_app_activity",
                  "type": {
                      "type": "record",
                      "name": "MobtabAvroMobileAppActivity",
                      "fields": [
                          {
                              "name": "app",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "start_time_usec",
                              "type": ["null", "string"],
                              "default": null
                          },
                          {
                              "name": "end_time_usec",
                              "type": ["null", "string"],
                              "default": null
                          }
                      ]
                  }
              }
          ]
      }
      Show
      {     "namespace": "fr.mediametrie.internet.pame.meter.avro",     "type": "record",     "name": "MobtabAvroHit",     "fields": [         {             "name": "time_usec",             "type": ["null", "string"],             "default": null         },         {             "name": "mobile_event_type",             "type": ["null", "string"],             "default": null         },         {             "name": "panelist_info",             "type": {                 "type": "record",                 "name": "MobtabAvroPanelistInfo",                 "fields": [                     {                         "name": "panel_id",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "panelist_id",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "household_id",                         "type": ["null", "string"],                         "default": null                     }                 ]             }         },         {             "name": "device_info",             "type": {                 "type": "record",                 "name": "MobtabAvroDeviceInfo",                 "fields": [                     {                         "name": "model_name",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "operating_system_name",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "operating_system_version",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "type",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "ad_id",                         "type": ["null", "string"],                         "default": null                     }                 ]             }         },         {             "name": "mobile_web_event",             "type": {                 "type": "record",                 "name": "MobtabAvroMobileWebEvent",                 "fields": [                     {                         "name": "url",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "user_agent",                         "type": ["null", "string"],                         "default": null                     }                 ]             }         },         {             "name": "mobile_app_activity",             "type": {                 "type": "record",                 "name": "MobtabAvroMobileAppActivity",                 "fields": [                     {                         "name": "app",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "start_time_usec",                         "type": ["null", "string"],                         "default": null                     },                     {                         "name": "end_time_usec",                         "type": ["null", "string"],                         "default": null                     }                 ]             }         }     ] }

    Description

      Hi,

      It seems there is a bug in the Avro library when generating the Avro source files from the Avro schema.
      As you could see in appendice, my schema is based on a main record and several sub-records.
      I work with "unions" for the type definition to allow setting fields to null when the value is not present.

      The issue is the following:
      First of all, this behavior isn't deterministic!
      When the library generates the source file, most of the sub-records are well generated (with null as the default value), but sometime, a single sub-record has its default value set to "null" (String). If I change the default value of the issued sub-record to "foo" and I re-generate the source file, I can see "foo" as the default value. If I rollback that change (back the default value to null) and I re-generate, I finally get null as default value (but not everytime ...).

      I think this issue is the source bug of the one I publish on Stackoverflow (directly see my second post):
      https://stackoverflow.com/questions/46775649/handle-nested-avro-record-when-the-one-is-null/46786313#46786313

      Any suggestions?

      Best regards,
      EddyA.

      Ps: its is always the same sub-record that is issued (mobile_web_event).

      Attachments

        Activity

          People

            Unassigned Unassigned
            EddyA Eddy ALBERT
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: