简体   繁体   English

如何在 bigquery 中获取计划查询的名称

[英]How to get names of scheduled queries in bigquery

Using a python client to connect with bigquery, how can we get names of all the scheduled queries present in that project?使用 python 客户端连接 bigquery,我们如何获取该项目中存在的所有计划查询的名称?

I tried following up with this link - https://cloud.google.com/bigquery/docs/reference/datatransfer/libraries我尝试跟进此链接 - https://cloud.google.com/bigquery/docs/reference/datatransfer/libraries

But got no information on the names of the scheduled queries.但是没有关于预定查询名称的信息。

To list all the scheduled queries for a project with Python BigQuery Client :要使用Python BigQuery Client列出项目的所有计划查询:

def get_scheduled_queries_configs():
    from google.cloud import bigquery_datatransfer

    transfer_client = bigquery_datatransfer.DataTransferServiceClient()

    project_id = "{project_id}"
    parent = transfer_client.common_location_path(project=project_id, location='EU')

    request = bigquery_datatransfer.ListTransferConfigsRequest(
        parent=parent,
        data_source_ids=['scheduled_query']
    )

    configs = transfer_client.list_transfer_configs(request=request)
    print("Got the following configs:")
    for config in configs:
        print(f"\tID: {config.name}, Schedule: {config.schedule}")
        print(f"\tDisplay name: {config.display_name}")

        config_name = config.name
        config_schedule = config.schedule
        config_display_name = config.display_name

    return configs


if __name__ == '__main__':
    scheduled_queries_configs = get_scheduled_queries_configs()

Some explanations:一些解释:

  • This code retrieves transfer configs only for scheduled queries via ListTransferConfigsRequest object. The request takes the parent argument containing the project and the location EU in this example.此代码仅通过ListTransferConfigsRequest object 检索计划查询的transfer configs 。在本示例中,该请求采用包含项目和位置EU的父参数。 The request take also data_source_ids argument with scheduled_query value该请求还采用带有scheduled_query值的data_source_ids参数
  • The location is important because if your scheduled queries are in US and you execute the request in EU, the result will be empty该位置很重要,因为如果您的预定查询在美国而您在欧盟执行请求,则结果将为空
  • The config.display_name allows to retrieve the name of a scheduled query config.display_name允许检索计划查询的名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式获取 bigquery 的计划查询执行日志? - How to get bigquery's scheduled queries execution log programmatically? 在 BigQuery Google Cloud 中获取我所有计划的 SQL 查询 - Get all my scheduled SQL queries in BigQuery Google Cloud 如何在 BigQuery 计划查询错误消息中动态包含值? - How to include values dynamically in BigQuery Scheduled Queries Error Message? BigQuery 仅在工作日安排的查询 - BigQuery Scheduled queries only on working days 在 bigquery 上运行 dbt 与预定查询 - Running dbt vs scheduled queries on bigquery 如何在视图或计划查询之间进行选择,以对通过 Stitch 导入的 BigQuery 表进行重复数据删除? - How to choose between Views or Scheduled Queries for de-duplicating BigQuery tables imported via Stitch? 如何在计划查询中显示和更改用户 - How to show and change user in Scheduled Queries BigQuery 计划查询 - 创建表并在不同项目中为其名称添加日期后缀 - BigQuery scheduled queries - Create table and add date suffix to its name in a different project 根据列值在 bigquery 中获取列名 - get column names in bigquery based on the column value 解决 BigQuery“启用计划查询 API 时发生错误”所需的权限。 问题 - What permissions required to solve BigQuery "An error occurred while enabling the Scheduled Queries API." problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM