正如 Adam 提到的,您可以使用 API 上的表 PATCH 方法来更新架构列。另一种方法是使用 bq。
您可以首先通过执行以下操作来获取架构:
1:获取 JSON 模式:
TABLE=publicdata:samples.shakespeare
bq show --format=prettyjson ${TABLE} > table.txt
Run Code Online (Sandbox Code Playgroud)
然后将架构从 table.txt 复制到 schema.txt ...它看起来像:
[
{
"description": "A single unique word (where whitespace is the delimiter) extracted from a corpus.",
"mode": "REQUIRED",
"name": "word",
"type": "STRING"
},
{
"description": "The number of times this word appears in this corpus.",
"mode": "REQUIRED",
"name": "word_count",
"type": "INTEGER"
},
....
]
Run Code Online (Sandbox Code Playgroud)
2:将描述字段设置为您想要的任何内容(如果不存在,请添加它)。
3:告诉 BigQuery 使用添加的列更新架构。请注意,schema.txt 必须包含完整的架构。
bq update --schema schema.txt -t ${TABLE}
Run Code Online (Sandbox Code Playgroud)
小智 7
BigQuery 现在支持 ALTER COLUMN SET OPTIONS 语句,该语句可用于更新列的描述
例子:
ALTER TABLE mydataset.mytable
ALTER COLUMN price
SET OPTIONS (
description="Price per unit"
)
Run Code Online (Sandbox Code Playgroud)
文档:
您可以使用 REST API 创建或更新表,并在架构中指定字段描述 (schema.fields[].description)。
https://cloud.google.com/bigquery/docs/reference/v2/tables#methods