2

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

运行这个 python 片段

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包版本

  • 谷歌 api 核心 (1.1.0)
  • 谷歌身份验证 (1.4.1)
  • 谷歌云大查询(0.31.0)
  • 谷歌云核心(0.28.1)
  • 谷歌可恢复媒体 (0.3.1)
  • googleapis-common-protos (1.5.3)

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

预先感谢您的帮助问候

4

2 回答 2

1

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

于 2018-04-02T20:50:46.177 回答
0

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

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

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

于 2018-03-29T14:19:13.833 回答