gpt4 book ai didi

null - Avro模式。如何一次将类型设置为 "record"和 "null"

转载 作者:行者123 更新时间:2023-12-04 17:17:07 28 4
gpt4 key购买 nike

我需要在架构中将“记录”类型与空类型混合使用。

"name":"specShape",
"type":{
"type":"record",
"name":"noSpecShape",
"fields":[
{
"name":"bpSsc",
"type":"null",
"default":null,
"doc":"SampleValue: null"
},...

例如,对于某些数据,specShape可以为null。

因此,如果我将类型设置为
"name":"specShape",
"type":{
**"type":["record", "null"],**
"name":"noSpecShape",
"fields":[
{
"name":"bpSsc",
"type":"null",
"default":null,
"doc":"SampleValue: null"
},...

它说
No type: {"type":["record","null"]...

但是如果我将whoole类型设置为
"name":"specShape",
**"type":[{
"type":"record",
"name":"noSpecShape",
"fields":[
{
"name":"bpSsc",
"type":"null",
"default":null,
"doc":"SampleValue: null"
}, "null"]**,...

它说
Not in union [{"type":"record"

如何结合这两种类型?

最佳答案

您有一个正确的想法,您只需要在更高级别的"null"数组中包括"type"即可,而不是在"fields"数组内部即可(如您的第三个示例)。这是可为空的记录的架构:

[
"null",
{
"type": "record",
"name": "NoSpecShape",
"fields": [
{
"type": "null",
"name": "bpSsc",
"default": null
}
]
}
]

您还可以将其嵌套在需要进行类型声明的任何位置,例如在另一个记录中:
{
"type": "record",
"name": "SpecShape",
"fields": [
{
"type": [
"null",
{
"type": "record",
"name": "NoSpecShape",
"fields": [
{
"type": "null",
"name": "bpSsc",
"default": null
}
]
}
],
"name": "shape"
}
]
}

最后一个模式的JSON编码实例如下所示:
  • {"shape": null}
  • {"shape": {"NoSpecShape": {"bpSsc": null}}}
  • 关于null - Avro模式。如何一次将类型设置为 "record"和 "null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36321616/

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