计划查询是 BigQuery 数据传输服务的一部分,因此您必须使用其 API。特别是projects.transferConfigs.list 方法。用scheduled_query 填写dataSourceIds 字段,用projects/PROJECT_ID 填写parent。正如 cmets 中所讨论的,如果您使用的是区域位置,例如 europe-west2,而不是多区域位置(欧盟或美国),则应改用 projects.locations.transferConfigs.list。现在,父资源将采用projects/PROJECT_ID/locations/REGIONAL_LOCATION 的形式。
另外,对于其他转账,您可以使用projects.dataSources.list方法获取对应的dataSourceIds。这就是我得到scheduled_query 的方式。
响应将是一组预定查询,例如:
{
"name": "projects/<PROJECT_NUMBER>/locations/us/transferConfigs/<TRANSFER_CONFIG_ID>",
"destinationDatasetId": "<DATASET>",
"displayName": "hacker-news",
"updateTime": "2018-11-14T15:39:18.897911Z",
"dataSourceId": "scheduled_query",
"schedule": "every 24 hours",
"nextRunTime": "2019-04-19T15:39:00Z",
"params": {
"write_disposition": "WRITE_APPEND",
"query": "SELECT @run_time AS time,\n title,\n author,\n text\nFROM `bigquery-public-data.hacker_news.stories`\nLIMIT\n 1000",
"destination_table_name_template": "hacker_daily_news"
},
"state": "SUCCEEDED",
"userId": "<USER_ID>",
"datasetRegion": "us"
}
使用 bash 和 curl 的 API 调用示例:
#!/bin/bash
# parameter(s)
location=europe-west2
authToken="$(gcloud auth print-access-token)"
projectId=$(gcloud config get-value project 2>\dev\null)
# API call
scheduled_queries=$(curl -H "Authorization: Bearer $authToken" \
https://bigquerydatatransfer.googleapis.com/v1/projects/$projectId/locations/$location/transferConfigs?dataSourceIds=scheduled_query)
# pretty print results
echo $scheduled_queries | python -m json.tool