0

I have a problem where my record json can be null. How to handle null records in avro schema? The documentation given is for null attributes I want to get for null records.

G.D
  • 1
  • 1
  • Take a look at this question, please: https://stackoverflow.com/questions/58591386/avro-optional-nullable-field – Vladislav Varslavans Apr 06 '20 at 13:29
  • Or this one: https://stackoverflow.com/questions/29299610/is-it-possible-to-have-an-optional-field-in-an-avro-schema-i-e-the-field-does – Vladislav Varslavans Apr 06 '20 at 13:30
  • Does this answer your question? [Is it possible to have an optional field in an Avro schema (i.e. the field does not appear at all in the .json file)?](https://stackoverflow.com/questions/29299610/is-it-possible-to-have-an-optional-field-in-an-avro-schema-i-e-the-field-does) – Vladislav Varslavans Apr 06 '20 at 13:30
  • The given links shows how to handle null attributes but I want to handle null records. – G.D Apr 07 '20 at 14:57
  • Please provide more details. Illustrate your example of null record. – Vladislav Varslavans Apr 07 '20 at 15:39
  • I am having the below JSON structure. You can the see the first record contains the sub-object 'Address' which does not contain any records, while the seconmd Record contains sub-object 'Address' and this sub-object contains sub-attributes -street and zip_code. So I need a way by which I can define that the attribute Address can be null. As per acro documentation this works well with normal attribute like 'name' but not working with 'address'. Ex: [ {"Record": {"name": "ABC","age": 22, "Address":{}}, {"Record": {"name": "XYZ","age": 29, "Address":{"street": "XYZ","zip_code": 123456}} ] – G.D Apr 08 '20 at 17:47

1 Answers1

0

the same applies to record types too. you can union the type with null.

{
  "name": "SpokenLanguage",
  "type": [
    "null",
    {
      "type": "record",
      "name": "Language",
      "fields": [
        {
          "name": "IsoCode",
          "type": [
            "null",
            "string"
          ],
          "default": null
        },
        {
          "name": "isPrimary",
          "type": "boolean",
          "default": false
        },
        {
          "name": "description",
          "type": [
            "null",
            "string"
          ],
          "default": null
        }
      ]
    }
  ],
  "default": null
}
arvin_v_s
  • 1,036
  • 1
  • 12
  • 18