要将标签附加到 BigQuery 表,第一步是使用下面的 Datacatalog api url 向上搜索表
LookupEntryRequest
我传递给下面的响应的参数是
sqlResource: "bigquery.table.myproject.zz_DataSet.tblOne"
上面应该给你输出
{
"name": "projects/myproject/locations/australia-southeast2/entryGroups/@bigquery/entries/mykey",
"type": "TABLE",
"schema": {
"columns": [
{
"type": "STRING",
"mode": "NULLABLE",
"column": "firstname"
},
{
"type": "STRING",
"mode": "NULLABLE",
"column": "lastname"
}
]
},
"sourceSystemTimestamps": {
"createTime": "2023-01-16T04:22:49.397Z",
"updateTime": "2023-01-16T04:22:49.397Z"
},
"linkedResource": "//bigquery.googleapis.com/projects/myproject/datasets/zz_DataSet/tables/tblOne",
"bigqueryTableSpec": {
"tableSourceType": "BIGQUERY_TABLE"
},
"usageSignal": {
"updateTime": "2023-02-05T07:59:59.928Z",
"usageWithinTimeRange": {
"30D": {
"totalCompletions": 7,
"totalFailures": 1,
"totalExecutionTimeForCompletionsMillis": 7385
}
}
},
"integratedSystem": "BIGQUERY",
"fullyQualifiedName": "bigquery:myproject.zz_DataSet.tblOne"
}
搜索使您能够查询多个表或在数据集级别附加标签,请参阅上面链接中的参数部分。
这就是为什么我建议您首先使用条目查找作为其更具可扩展性的代码。
- API 调用二:这就是我如何模拟附加标签到资源。如果你去下面的链接
CreateTagRequest
例如:我从控制台预先创建了一个标签模板,然后使用模板 ID 值作为参数传递给请求
输入:
parent: projects/myproject/locations/australia-southeast2/entryGroups/@bigquery/entries/mykey 来自上面的名称元素
请求正文:
{
"template": "projects/myproject/locations/australia-southeast1/tagTemplates/api_call_test_tag_template",
"fields": {
"name": {
"stringValue": "apitestcall"
}
}
}
输出:下面是生成的响应,如果您在数据目录控制台中看到,您将看到 bigquery 表附加了标签模板,名称字段的值附加为“apitestcall”。见附件
{
"name": "projects/myproject/locations/australia-southeast2/entryGroups/@bigquery/entries/mykey/tags/tagsKey",
"template": "projects/myproject/locations/australia-southeast1/tagTemplates/api_call_test_tag_template",
"fields": {
"name": {
"displayName": "name",
"stringValue": "apitestcall"
}
},
"templateDisplayName": "api-call-test-tag-template"
}
最后,请务必确保您拥有此任务所需的所有正确 IAM 权限。