When writing Avro schema I often forget the how to construct certain constructs which are provided by Avro Schema itself. For my own sake I decided to keep a list of often used features.
Union types and null
Union types are capability of Avro Schema to support multiple types within the same field. I use this feature commonly to create a union of some type and null, and to mark the null the default case. When Avro generates the classes for Java, these fields can then be omitted or set to null.
{"name": "someField", "type": ["null", "string"], "default": null},
Field ordering compatibility
When defining Avro schema, it is important to add fields to the end of the “field” array. This is because Avro uses implicit field indexes when deserializing binary streams.