【问题标题】:Export bigQuery table to google data storage runs into AttributeError exception将 bigQuery 表导出到谷歌数据存储时遇到 AttributeError 异常
【发布时间】:2018-09-05 02:44:24
【问题描述】:

我正在尝试将表从谷歌 bigQuery 导出到谷歌数据存储作为 json 文件。

运行这个 python sn-p

from google.cloud import bigquery

client = bigquery.Client()
bucket_name = 'mybucket'

destination_uri = 'gs://{}/{}'.format(bucket_name, 'myfile.json')
dataset_ref = client.dataset('mydataset')
table_ref = dataset_ref.table('mytable')
job_config = bigquery.job.ExtractJobConfig()
job_config.destination_format = (
    bigquery.DestinationFormat.NEWLINE_DELIMITED_JSON)

extract_job = client.extract_table(
    table_ref, destination_uri, job_config=job_config
    )
extract_job.result()

我收到了这个错误

AttributeError: module 'google.cloud.bigquery' has no attribute 'DestinationFormat'

我按照官方文档 https://cloud.google.com/bigquery/docs/exporting-data#configuring_export_options

这里是我的 python 包版本

  • google-api-core (1.1.0)
  • google-auth (1.4.1)
  • google-cloud-bigquery (0.31.0)
  • google-cloud-core (0.28.1)
  • google-resumable-media (0.3.1)
  • googleapis-common-protos (1.5.3)

最新的包/文档怎么可能收到这个错误?

提前感谢您的帮助 问候

【问题讨论】:

    标签: google-cloud-platform google-bigquery google-python-api


    【解决方案1】:

    您可以尝试将bigquery.DestinationFormat.NEWLINE_DELIMITED_JSON 替换为bigquery.job.DestinationFormat.NEWLINE_DELIMITED_JSON 吗?这可能是文档中的错误。

    【讨论】:

    【解决方案2】:

    确保本地安装的版本具有所需的属性,也许你有一个旧版本:打开 Python 控制台,导入 bigquery,然后 dir it 或 help(bq) 等查看属性是否存在。如果不是,请 pip 更新 gcloud 包并重试。

    如果从 Python shell 中该属性确实存在,但不是在您运行脚本时,则必须安装第二个 Python 版本。

    可能还有其他原因,但让我们看看您发现了什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-07
      • 2017-12-03
      • 2017-02-10
      • 2018-11-15
      • 2020-02-15
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多