【问题标题】:Google Bigquery API: How to get the name of temporary tableGoogle Bigquery API:如何获取临时表的名称
【发布时间】:2016-10-22 12:18:16
【问题描述】:

我知道:查询的结果会保存在一个临时表中。但是如何让它的名字在其他查询中使用。

from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from oauth2client.client import GoogleCredentials

def test():
    project_id = "598330041668"
    credentials = GoogleCredentials.get_application_default()
    bigquery_service = build('bigquery', 'v2', credentials=credentials)
    # [START run_query]
    query_request = bigquery_service.jobs()
    query_data = {
        'query': (
            'SELECT * '
            'FROM [test.names];')
    }

    query_response = query_request.query(
        projectId=project_id,
        body=query_data).execute()
    # [END run_query]

【问题讨论】:

  • 粘贴您的代码...
  • 嗨@SmitaAhinave,我添加了代码。谢谢:)

标签: python google-bigquery temp-tables


【解决方案1】:
  1. 查找您运行的查询的作业 ID。这出现在来自 jobs.query 的响应中,位于 jobReference 字段中。
  2. 使用jobs.get 方法查找您运行的作业的查询配置。检查字段configuration.query.destinationTable

但是,请注意,如果您没有指定自己的目标表,BigQuery 会分配 a temporary one that should only be used in certain APIs, which does not include other queries

此方法的查询结果将保存到一个临时表中,该表在查询运行大约 24 小时后被删除。您可以通过调用 bigquery.tabledata.list(table_id) 或 bigquery.jobs.getQueryResults(job_reference) 来读取此结果表。 表和数据集名称是非标准名称,不能在任何其他 API 中使用,因为其行为可能无法预测。

如果您想在后续查询中使用查询的结果,我建议您自己设置configuration.query.destinationTable 以写入您选择的表。

【讨论】:

  • 是的。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-07
  • 1970-01-01
  • 1970-01-01
  • 2019-03-06
  • 1970-01-01
  • 2012-07-05
  • 2017-04-01
相关资源
最近更新 更多