问题的根源是在新版本的Avro中,枚举联合类型应该有一个有效的默认值。如果没有显式提供默认值,则默认值应为null。但是在旧版中,如果没有默认值,则假定第一个声明的元素是默认值。
因此,为了解决此问题,您需要显式提供每个枚举联合类型的默认值。以下是示例代码:
{
"type" : "record",
"name" : "example_record",
"fields" : [
{
"name" : "enum_union",
"type" : [
"null",
{
"type" : "enum",
"name" : "example_enum",
"symbols" : [
"SYMBOL1",
"SYMBOL2",
"SYMBOL3"
],
"default": null
}
],
"default": null
}
]
}
在上面的代码示例中,我们为枚举联合类型提供了默认值为null,这将消除版本之间的兼容性问题。