Importance of logical types in Avro
The importance of logical types in Avro format for Schema Registry can be represented with an example using a decimal logical type.
Huge numbers that cannot be stored in a long type with 8 bytes can be stored as byte arrays with decimal logical type using Avro. This means that the data will be stored as a byte array, which is flexible, but it also means that when you parse the data from Avro, you need additional information, the logical type, to interpret the raw data, the byte array, properly. By default, you will only get a byte array for this kind of field value, and you have to parse that byte array for the required logical type. Each Avro logical type has their own Java classes that they can be parsed for. Decimal logical type has BigDecimal in Java.
If you use generated classes, such as specific classes, on the classpath for Avro, the
conversion happens automatically based on the types in the classes. If you do not use specific
classes, Cloudera provides configuration to enable automatic conversion for logical type record
fields during serialization and deserialization. Check the
logical.type.conversion.enabled
flag. This flag has no effect if
specific.avro.reader
is set to true
, which means specific
classes are used.
For more information, see the Logical Types section in the official Avro documentation.