需要为 BigQuery 表的每一列添加描述,似乎我可以手动完成,如何以编程方式完成?
最佳答案
正如 Adam 所提到的,您可以使用 API 上的 table PATCH 方法来更新架构列。另一种方法是使用 bq。
您可以先通过执行以下操作来获取架构:
1:获取JSON模式:
TABLE=publicdata:samples.shakespeare
bq show --format=prettyjson ${TABLE} > table.txt
然后将模式从 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"
},
....
]
2:将描述字段设置为您想要的任何内容(如果不存在,请添加它)。
3:告诉 BigQuery 使用添加的列更新架构。请注意,schema.txt 必须包含完整的架构。
bq update --schema schema.txt -t ${TABLE}
关于google-bigquery - 向 BigQuery 表添加列描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30007888/