linkedin / avro-util

Collection of utilities to allow writing java code that operates across a wide range of avro versions.
BSD 2-Clause "Simplified" License
76 stars 60 forks source link

Avro 1.9+ dropping defaults #298

Open majisourav99 opened 2 years ago

majisourav99 commented 2 years ago

The helper builder drops the default value if the default value type does not match, eg if 0 is a default value of field type float then the following code will silently drop the default

public FieldBuilder19(Schema.Field other) { if (other != null) { _name = other.name(); _schema = other.schema(); _doc = other.doc(); _defaultVal = other.defaultVal(); // Its null for Avro 1.9+ _order = other.order(); // other.order() cannot be null under Avro 1.9.* _props = other.getObjectProps(); } }

srramach commented 2 years ago

Are you asking for an exception to be thrown, instead of silently dropping the default?

majisourav99 commented 2 years ago

Using the avro-util AvroCompatibilityHelper default getter method, we should set the correct default value.

srramach commented 2 years ago

I think it's more correct to throw an exception. Silently turning invalid default values into valid ones seems like it would just mask issues that originate/happen elsewhere.

radai-rosenblatt commented 2 years ago

there is a bug in avro 1.9 if int default values are provided for float fields. we should be able to work around it in helper code. also worth having a spotbugs rule for use of the defaultVal() method perhaps as it is vulnerable to this bug in 1.9?