Avro 架构不向后兼容

时间:2021-04-19 12:16:51

标签: avro confluent-schema-registry idl

我有一个 avro 架构定义,如 -

    @namepsace("com.test.customer)
protocol customerData {
    record customerData {
        union {null, string} id;
        union {null, string} firstname;
    }
}

上线后,我们添加了另一个字段 -

@namepsace("com.test.customer)
protocol customerData {
    record customerData {
        union {null, string} id;
        union {null, string} firstname,
        union {null, string} customerType
    }
}

customerType 定义为空字符串。即使在使用融合注册表注册架构时,我们也会收到错误 - 正在注册的架构与较早的架构不兼容。

如果背后有任何原因,请告诉我们。我们已通过将 customerType 显式默认为 null 来解决此问题,

union {null, string} customerType = null;

但不知何故,我觉得这不是必需的。请让我知道为什么即使架构定义为 {null, string}

也会出现错误

1 个答案:

答案 0 :(得分:0)

"union {null, string} customerType" 表示 customerType 可以为 null,但默认为 undefined。默认可以是任何东西,比如

union {null, string} customerType = ""; (空)

union {null, string} customerType = null;

您必须指定一个默认值,以便在缺少字段时,Avro 知道该字段使用什么。