gpt4 book ai didi

java - Apache Avro 的 Java 中 Union 的默认值是多少?

转载 作者:行者123 更新时间:2023-12-02 09:02:02 24 4
gpt4 key购买 nike

我正在尝试设置字段的默认值(使用 Java),但遇到了一个令人讨厌的异常:

Exception in thread "main" org.apache.avro.AvroTypeException: Invalid default for field first: "Andy" not a ["null","string"]

at org.apache.avro.Schema.validateDefault(Schema.java:1542)

Apache Avro: Unions 的文档说:

Unions, as mentioned above, are represented using JSON arrays. For example, ["null", "string"] declares a schema which may be either a null or string.

(Note that when a default value is specified for a record field whose type is a union, the type of the default value must match the first element of the union. Thus, for unions containing "null", the "null" is usually listed first, since the default value of such unions is typically null.)

有人可以告诉我为什么默认值的类型必须与联合的第一个元素匹配吗?

最佳答案

似乎您需要更改为 ["string","null"] 因为默认值将是第一个,并且您的默认值是字符串。

关于java - Apache Avro 的 Java 中 Union 的默认值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60091156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com