Search code examples
avroapache-kafka-connect

AvroData replaces nulls with schema default values


i'm using io.confluent.connect.avro.AvroData.fromConnectData to convert message before serialization. AvroData uses struct.get(field) to get values which in turn replaces nulls with schema default values.

as i understand from avro doc default values should be used for schema compatibility when reader expects field that missing in writer schema (not particular message).

so my question is: is it correct way to replace nulls with schema default value? or maybe i should use another way to convert messages?


Solution

  • The miss understanding is that the default value is not used to replace null values, it is used to populate your field value in case that your data does not include the field. This is primary used for schema evolution purposes. What you are trying to do (replace null values coming as part of your data with another value) is not possible through avro schemas, you will need to deal with it in your program.