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

标签 java avro

我正在尝试设置字段的默认值(使用 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/

相关文章:

java - 为什么 JPA 使用 javax.persistence.NoResultException

amazon-web-services - 尝试访问 Amazon Redshift 外部表时出错

java - 使用 Python 读取 AVRO 文件

java - 模式注册表中的关键模式是什么?

python-3.x - 使用 Python3 处理 AVRO 的嵌套模式

java - 包 org.apache.poi.ss.usermodel 不存在错误

java - 带有地理空间查询的 MongoDb $and 运算符

java - 为什么Android获取类的声明字段是无序的?

java - 在 Recycler View 的情况下,等效的 listview.setSelection 是什么

scala - 如何在 Spark 中创建一个空的数据帧