如何在 BigQuery 中以编程方式添加字段描述 table

How to add field descriptions programmatically in BigQuery table

我想以编程方式在 bq table 中 添加字段描述 ,我知道如何在 UI 中执行。 我有这个要求是因为我的数据集中几乎没有每天刷新的 table,我们使用 "writeMode": "WRITE_TRUNCATE"。这也删除了table的所有字段名称的描述。

我还在我的架构文件中添加了 table 的描述,就像这样

                    {
                            "name" : "tax",
                            "type" : "FLOAT",
                            "description" : "Tax amount customer paid"
                    }

但是在 运行 加载数据的脚本之后,我在最终 table 中没有看到描述。

一些表 API (https://cloud.google.com/bigquery/docs/reference/v2/tables) 允许您设置 table 和模式的字段描述

您可以在
期间设置描述 table 创作 - https://cloud.google.com/bigquery/docs/reference/v2/tables/insert
或在使用以下 API 之一创建 table 之后:
补丁 - https://cloud.google.com/bigquery/docs/reference/v2/tables/patch
更新 - https://cloud.google.com/bigquery/docs/reference/v2/tables/update

我觉得,你的补丁API更合适table
link 下方显示了 table 可以使用这些 API 设置的资源 https://cloud.google.com/bigquery/docs/reference/v2/tables#resource

BigQuery 加载作业接受每个字段都包含 "description" 的架构。

https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load

如果您在 WRITE_TRUNCATE 操作期间指定描述以及您正在创建的每个字段,则描述应应用于目标 table。

这是上面 link 的一个片段,其中包含您指定的架构:

"load": {
  "sourceUris": [
    string
  ],
  "schema": {
    "fields": [
      {
        "name": string,
        "type": string,
        "mode": string,
        "fields": [
          (TableFieldSchema)
        ],
        "description": string
      }
    ]
  },