REPEATED列类型的PubSub订阅错误-Avro架构



我正在尝试使用PubSub Subscription"写入BigQuery";但我遇到了";重复的";列类型。更新订阅时收到的消息是

字段"Values"的架构模式不兼容:字段在主题架构中为REQUIRED,但在BigQuery表架构中为REPEATED

我的Avro架构是:

{
"type": "record",
"name": "Avro",
"fields": [
{
"name": "ItemID",
"type": "string"
},
{
"name": "UserType",
"type": "string"
},
{
"name": "Values",
"type": [
{
"type": "record",
"name": "Values",
"fields": [
{
"name": "AttributeID",
"type": "string"
},
{
"name": "AttributeValue",
"type": "string"
}
]
}
]
}
]
}

输入JSON;匹配";架构:

{
"ItemID": "Item_1234",
"UserType": "Item",
"Values": {
"AttributeID": "TEST_ID_1", 
"AttributeValue": "Value_1"
}
}

我的桌子看起来像:

ItemID | STRING | NULLABLE
UserType | STRING | NULLABLE
Values | RECORD | REPEATED
AttributeID | STRING | NULLABLE
AttributeValue | STRING | NULLABLE

我能够";测试";以及";验证模式";它回来时取得了成功。问题是,我在Avro for the Values节点上缺少什么来使其成为";重复的";vs";"必需";以便创建订阅。

问题是,Values在Avro架构中不是数组类型,这意味着它在消息中只需要一个,而在BigQuery架构中它是重复类型,意味着它需要它们的列表。

根据Kamal上面的评论,这个模式有效:

{
"type": "record",
"name": "Avro",
"fields": [
{
"name": "ItemID",
"type": "string"
},
{
"name": "UserType",
"type": "string"
},
{
"name": "Values",
"type": {
"type": "array",
"items": {
"name": "NameDetails",
"type": "record",
"fields": [
{
"name": "ID",
"type": "string"
},
{
"name": "Value",
"type": "string"
}
]
}
}
}
]
}

有效载荷:

{
"ItemID": "Item_1234",
"UserType": "Item",
"Values": [
{ "AttributeID": "TEST_ID_1" },
{ "AttributeValue": "Value_1" }
]
}

相关内容

最新更新