【问题标题】:How to get console view of parameterised BigQuery query?如何获取参数化 BigQuery 查询的控制台视图?
【发布时间】:2019-09-04 10:07:02
【问题描述】:

我正在一个 Flask 应用程序中运行参数化 BigQuery 查询,完全按照Google's docs 中的描述。

我看到了一些意想不到的结果,因此只想将查询打印到我的终端/控制台以进行调试。当我这样做时,只看到带有参数化占位符的查询,而不是值。

有谁知道如何通过正在运行的值查看查询的视图?

例如:

query = "select * from dogs where breed = @dog_breed"

query_params = [
    bigquery.ScalarQueryParameter("dog_breed", "STRING", "kokoni")
]

job_config = bigquery.QueryJobConfig()

job_config.query_parameters = query_params

print(query) # This will only print query as above, not with value 'kokoni'

query_job = client.query(
    query,
    job_config=job_config,
)  

【问题讨论】:

    标签: python google-bigquery


    【解决方案1】:

    您可以使用list_jobs 方法从Job class 中检索信息,如下例所示:

    from google.cloud import bigquery
    
    client = bigquery.Client()
    
    # List the 3 most recent jobs in reverse chronological order.
    # Omit the max_results parameter to list jobs from the past 6 months.
    print("Last 3 jobs:")
    for job in client.list_jobs(max_results=3):  # API request(s)
        print(job.query)
        print(job.query_parameters)
    

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-19
      相关资源
      最近更新 更多