I'm trying to put default value as integer for coming values from kafka it could be any integer or null. I was trying like this:
union {null, int} field = 2; (in avdl file)
but I'm getting error Error: Exception in thread "main" org.apache.avro.AvroTypeException: Invalid default for field field: 2 not a ["null","int"]
According to avro documentation:
Since
nullis the first element of the union, and2is notnull, avro is complaining about the invalid default value.If you want to set
2as the default value, you could declare the union asunion {int, null}.