我在BigQuery中有一个嵌套表A,其架构如下:
{
"name": "page_event",
"mode": "repeated",
"type": "RECORD",
"fields": [
{
"name": "id",
"type": "STRING"
}
]
}
我想用其他表中的数据来丰富表A,并将结果保存为新的嵌套表。假设我想在表A中添加“description”字段(创建表B),所以我的模式如下:
{
"name": "page_event",
"mode": "repeated",
"type": "RECORD",
"fields": [
{
"name": "id",
"type": "STRING"
},
{
"name": "description",
"type": "STRING"
}
]
}
如何在BigQuery中执行此操作?似乎没有在BigQuery SQL中创建嵌套结构的函数(除了NEST函数,它产生一个列表 - 但是这个函数似乎不起作用,失败并出现意外错误)
我能想到的唯一方法就是:
有更简单的方法吗?
答案 0 :(得分:1)
为了丰富现有表的模式,可以使用表补丁API https://cloud.google.com/bigquery/docs/reference/v2/tables/patch
请求将如下所示
PATCH https://www.googleapis.com/bigquery/v2/projects/{project_id}/datasets/{dataset_id}/tables/{table_id}?key={YOUR_API_KEY}
{
"schema": {
"fields": [
{
"name": "page_event",
"mode": "repeated",
"type": "RECORD",
"fields": [
{
"name": "id",
"type": "STRING"
},
{
"name": "description",
"type": "STRING"
}
]
}
]
}
}
补丁之前
补丁后