You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PubSub订阅写入BigQuery时REPEATED列类型不兼容问题排查

解决PubSub到BigQuery订阅的REPEATED列类型不匹配问题

你遇到的核心问题是Avro Schema里的Values字段定义的是单个Record类型,而BigQuery表中该字段是REPEATED(数组)类型,导致两者模式不兼容。下面是具体的修改方案:

修改后的Avro Schema

需要把Values字段的类型从单个Record改为数组类型,同时调整内部Record的命名避免冲突(原命名和字段名重复可能引发解析问题):

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

对应的输入JSON格式

因为Values现在是数组类型,输入JSON里需要把它改成数组结构(即使只有一个元素也要用数组包裹):

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

关键说明

  • Avro中数组类型的标准写法是{"type": "array", "items": <元素类型>},这样定义后,字段会被识别为可重复的集合类型,和BigQuery的REPEATED模式完全匹配。
  • 修改后重新验证Schema,再更新PubSub订阅,就能解决"Incompatible schema mode"的报错。

内容的提问来源于stack exchange,提问作者sherring

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 02:18:07