Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.9.0
-
None
Description
Currently, ThrifdData class produces not compatible avro schema in terms of AvroCompatibility rules.
For example, consider this thrift structs:
struct V1 { 1: required string f1, 2: optional string f2 } struct V2 { 1: required string f1, 2: optional string f2, 3: optional string f3 }
Produced schemas will be:
{"type":"record","name":"V1","namespace":"serialization.thrift.test","fields":[{"name":"f1","type":["null",{"type":"string","avro.java.string":"String"}]},{"name":"f2","type":["null",{"type":"string","avro.java.string":"String"}],"default":null}]} {"type":"record","name":"V2","namespace":"serialization.thrift.test","fields":[{"name":"f1","type":["null",{"type":"string","avro.java.string":"String"}]},{"name":"f2","type":["null",{"type":"string","avro.java.string":"String"}]}, {"name":"f3","type":["null",{"type":"string","avro.java.string":"String"}]}]}
The problem is that if i try to check this schemas using BACKWARD compatibility checker i will get false, because fields f2 and f3 has no default values even if they are optional.
Also, if i use default value in my thrift definition the resulting avro schema will not contain it.
There is possibility to fix default null values for optional fields using NULL_DEFAULT_VALUE, but it will ignore the real default values.
To get the real default values specified in *.thrift we can use instance of thrift message to get default value, but this will require some refactoring of such methods as getSchema and nullable in ThriftData.class