使用list_transfer_configs查看大查询中计划查询的状态

问题描述 投票:0回答:2

我正在尝试创建一个云函数,它将检查某些计划查询的状态,以便触发另一个进程。我正在尝试在 main.py 中使用下面的内容

from google.cloud import bigquery
from google.cloud import bigquery_datatransfer
def extract_data(event, context):
    transfer_client = bigquery_datatransfer.DataTransferServiceClient()
    project_id = "projects/whr-asia-datalake-nonprod"
    configs = transfer_client.list_transfer_configs(parent=project_id)
    print("Got the following configs:")
    for config in configs:
      print(f"\tID: {config.name}, Schedule: {config.schedule}")

在requirements.txt中,我添加了以下代码

google-cloud-bigquery-datatransfer==1
google-cloud-bigquery==1

enter image description here

得到空响应,如上所示。我已经安排了今天运行的查询。可能是什么问题?

python google-cloud-platform google-bigquery google-cloud-functions
2个回答
0
投票

我遇到了类似的问题,但只能看到一些查询。结果默认情况下它只提取来自美国的查询。

https://github.com/googleapis/google-cloud-python/issues/8466#issuecomment-610772303

不确定这是否完全是您的问题,但将位置添加到项目中,它应该从其他区域提取。

def get_scheduled_queries():
    transfer_client = bigquery_datatransfer.DataTransferServiceClient()
    parent = transfer_client.common_project_path(project_id + "/locations/EU")
    configs = transfer_client.list_transfer_configs(parent=parent)
    for config in configs:

0
投票

扩展 Redim 的答案 - 你的代码不起作用。在这里我做得更好:

from google.cloud import bigquery_datatransfer

transfer_client = bigquery_datatransfer.DataTransferServiceClient()
project_id = "your_project"
region_id = "your_region"
parent = transfer_client.common_location_path( project_id, region_id)
configs = transfer_client.list_transfer_configs(parent=parent)
print("Got the following configs:")
for config in configs:
    print(f"\tID: {config.name}, Schedule: {config.schedule}")
© www.soinside.com 2019 - 2024. All rights reserved.