Avro ENUM字段 [英] Avro ENUM field
本文介绍了Avro ENUM字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Avro模式中创建Union字段,并使用它发送相应的JSON消息,但是要使用其中一个字段-null
.
I am trying to create Union field in Avro schema and send corresponding JSON message with it but to have one of the fields - null
.
https://avro.apache.org/docs/1.8 .2/spec.html#Unions
最简单的UNION类型(avro模式)与相应的JSON数据的示例是什么? (尝试以不包含null/empty数据的示例和包含null/empty数据的示例为例).
What is example of simplest UNION type (avro schema) with corresponding JSON data? (trying to make example without null/empty data and one with null/empty data).
推荐答案
这里有一个例子.
空枚举
{"name": "Stephanie", "age": 30, "sex": "female", "myenum": null}
不是空的枚举
{"name": "Stephanie", "age": 30, "sex": "female", "myenum": "HEARTS"}
模式
{
"type": "record",
"name": "Test",
"namespace": "com.acme",
"fields": [{
"name": "name",
"type": "string"
}, {
"name": "age",
"type": "int"
}, {
"name": "sex",
"type": "string"
}, {
"name": "myenum",
"type": ["null", {
"type": "enum",
"name": "Suit",
"symbols": ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
}
]
}
]
}
这篇关于Avro ENUM字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文