【问题标题】:How to use projection_fields parameter in Bigquery Python API如何在 Bigquery Python API 中使用 projection_fields 参数
【发布时间】:2019-11-30 00:19:25
【问题描述】:

我正在尝试使用 Python API 将 Google Cloud Storage 中的 Cloud Firestore 导出加载到 Bigquery。我只需要加载几个我想使用 --projection_fields 参数的字段。但是,我无法在我的代码中成功使用此参数。我指的是这个文档:https://cloud.google.com/bigquery/docs/loading-data-cloud-firestore

我正在使用 google.cloud 库。

在 bigquery 或 firestore 库中找不到此字段。

任何有关如何使用 Python API 使用此字段的提示都会有很大帮助。

import os
from google.cloud import bigquery

creds_file_path = "xxxx.json"
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = creds_file_path

bigquery_client = bigquery.Client()
dataset_ref = bigquery_client.dataset('abcd')
job_config = bigquery.LoadJobConfig()
job_config.write_disposition = bigquery.WriteDisposition.WRITE_TRUNCATE
job_config.source_format = bigquery.SourceFormat.DATASTORE_BACKUP

【问题讨论】:

  • 你最终设法让它工作了吗?

标签: python google-cloud-firestore google-bigquery


【解决方案1】:

查看pyhon客户端库changelog好像还不支持这个选项。但是,您可以使用此解决方法来包含 projectionFields 属性,以及客户端尚不支持但适用于 API 的任何属性。

my_list_of_properties = [] # The properties you want to include on the table    
job_config._set_sub_prop('projectionFields', my_list_of_properties)

【讨论】:

    猜你喜欢
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多