如何在Google Pub/Sub Topic Schema中声明可选字段



我正试图在AVRO上创建一个Pub/Sub-Schema主题,该主题涉及带有"default" : null指示的文档上的指示。我这样声明我的可选字段:

{
"name": "myField",
"type": ["null","string"],
"default": null
}

我得到的错误:

Incorrect token in the stream. Expected: Object start, found String

你知道如何解决这个问题吗?

不确定这是否正是你想要的,但我可能会尝试这样的东西:

{
"type": "record",
"name": "SomeName",
"fields": [
{
"name": "myField",
"type": ["string", "null"]
}
]
}

如Apache Avro规范中定义的,以及PubSub Schema创建中描述的

@Snowfire,您在评论中提到,您选择继续使用无模式主题。

您可以按照本文档创建发布/子架构。

要创建Avro类型的模式,您可以尝试以下操作:

{
"type": "record",
"name": "Avro",
"fields": [
{
"name": "testname",
"type": ["null", "string"],
"default": null
},
{
"name": "testId",
"type": ["null", "int"],
"default": null
}
]
}

我根据模式测试了下面的消息,它是有效的。

{
"testname": {
"string": "Jack"
},
"testId": {
"int": 101
}
}

最新更新