Vamsi Subhash Achanta created AVRO-2248:
-------------------------------------------
Summary: Added support for Java parameterised types with
ReflectData in Avro
Key: AVRO-2248
URL: https://issues.apache.org/jira/browse/AVRO-2248
Project: Avro
Issue Type: Improvement
Components: java
Affects Versions: 1.8.2
Reporter: Vamsi Subhash Achanta
Hi all,
Avro doesn't have support for Parameterised types currently. Ex:
class Pair<K,V> {
K key;
V value;
}
For the above class, the schema generation fails when using ReflectData and
ReflectDatumWriter. This is because the type information is not handled within
the avro code and is not passed over.
For Map/Collection, it is explictly hardcoded and supported within the code but
for other generic types, it is not. The fix is modelled on how Map is solved
internally and generalises it for all generic type parameters.
The fix (and patch attached) addresses this by adding a new type called PARAM
(like MAP) and is handled in all places including:
* schema generation using ReflectData..getSchema(..
* schema parsing using Schema.Parser
* serialization to bytes using ReflectDatumWriter
* de-serialization from bytes to object using ReflectDatumReader
The test for the above cases is included in the patch and we have tested it
with ~15 level nested type param schemas in our codebase internally here. The
current code works for our cases. We are open to fixing bugs that might arise
out of this if any.
Please help us mainline this into avro code as it can be a very useful feature
to all. Thanks a lot for the great project!
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)