I have an avro schema define like -
@namepsace("com.test.customer)
protocol customerData {
record customerData {
union {null, string} id;
union {null, string} firstname;
}
}
after it went live, we added another field -
@namepsace("com.test.customer)
protocol customerData {
record customerData {
union {null, string} id;
union {null, string} firstname,
union {null, string} customerType
}
}
customerType is defined as null, string. even then when while registering the schema with the confluent registry, we get the error - Schema being registered is incompatible with an earlier schema.
Please let us know if there is any reason behind it. we have fixed this by explicitly defaultting customerType to null,
union {null, string} customerType = null;
But somehow I feel that this is not required. Please let me know why we get the error even when the schema is defined as {null, string}
"union {null, string} customerType" means that customerType can be null, but the default is undefined. The default can be anything, like
union {null, string} customerType = ""; (empty)
union {null, string} customerType = null;
You have to specify a default value so that when the field is missing, Avro knows what to use for the field.