There is a conversion for values of type short (and other numeric types) if in the schema they are declared as int:
So, if a value of short type is passed to INT field, it will be converted and saved as INT in avro.
But, when there is next field in schema:
which is a union with int in it, and short is passed in (lets say 5), then we are having the next exception:
This happens because in org.apache.avro.generic.GenericData there is no check if the passed object has a type of java.lang.Short, and it is not get converted then in write method of GenericDatumWriter:
This error initially occured during thrift to avro conversion, when thrift obj had optional field of type i16.
In thrift to avro schema converter, if the type is short in thrift (i16) it will be implicitly converted to int in avro-schema, so the values should be converted as well. This is already done if they are not in the union (not optional). Otherwise the exception is thrown.
The snippet from schema conversion code is below:
Proposal is to add isShort check to generic data, as well as isShort method implementation:
or maybe even some kind of isNumeric method, so the behaviour will be same for INT fields and INT fields that are in Union.