【发布时间】:2022-01-02 11:12:34
【问题描述】:
在Confluent documentation 中,他们写道,删除和添加可选的 AVRO 字段可保持完整的 AVRO 兼容性。我需要通过删除可选字段和添加新的可选字段来更新 AVRO 模式。但是 Confluent 架构注册表响应错误 409,即新架构与旧架构不兼容。
我正在删除以下字段(在 avsc 语法中):
{
"name" : "eligibility",
"type" : [ {
"type" : "array",
"items" : "Scope"
}, "null" ]
}
并添加这些字段:
{
"name" : "partyDataExt",
"type" : [ {
"type" : "record",
"name" : "PartyDataExt",
"fields" : [ {
"name" : "dayOfDeath",
"type" : [ {
"type" : "int",
"logicalType" : "date"
}, "null" ]
}, {
"name" : "identified",
"type" : [ "boolean", "null" ]
} ]
}, "null" ]
}
和
{
"name" : "identificationDocument",
"type" : [ "null", "Document" ]
}
问题:可选的 AVRO 字段究竟是什么意思?是union {null, MyType},还是default参数的存在,或者两者兼而有之,还是别的什么?
在删除“资格”字段的情况下,如果该字段具有"default":null 会有所帮助。这也有助于添加的“identificationDocument”字段,但不适用于“partyDataExt”字段。
当我在“identificationDocument”的定义中切换"null" 和"Document" 元素时,添加default 参数也无济于事。看来"null" 必须是"type" 数组中的第一个元素。
【问题讨论】:
-
根据Avro specification,联合字段的默认值对应联合中的first模式。
-
@ChinHuang 不幸的是,这不足以让 Confluent 模式注册表接受模式更改作为兼容。
"default":null字段参数似乎也是必要的。但这只是一个反复试验的结果,文档很模糊。
标签: avro confluent-schema-registry