Google Cloud BigQuery load_table_from_dataframe()Parquet attribute

2024-04-23 10:26:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用BigQuery包与Pandas数据帧交互。在我的场景中,我在BigQuery中查询一个基表,使用.to_dataframe(),然后将其传递给load_table_from_dataframe()以将其加载到BigQuery中的新表中。在

我最初的问题是(uuid.uuid4())(对于随机标识)被自动转换为字节而不是字符串,因此我强制使用一个模式,而不是允许它自动检测生成的内容。在

不过,现在我传递了一个job_config dict,其中包含模式,现在我得到了这个错误:

File "/usr/local/lib/python2.7/dist-packages/google/cloud/bigquery/client.py", line 903, in load_table_from_dataframe

job_config.source_format = job.SourceFormat.PARQUET AttributeError: 'dict' object has no attribute 'source_format'

我已经安装了PyArrow,还尝试安装了FastParquet,但它没有帮助,而且在我尝试强制一个模式之前,这并没有发生。在

有什么想法吗?在

https://google-cloud-python.readthedocs.io/en/latest/bigquery/usage.html#using-bigquery-with-pandas

https://google-cloud-python.readthedocs.io/en/latest/_modules/google/cloud/bigquery/client.html#Client.load_table_from_dataframe

从实际的包来看,它似乎强制使用Parquet格式,但正如我所说的,我以前没有问题,现在我正试图给出一个表模式。在

编辑:只有当我试图写入BigQuery时才会发生这种情况。在


Tags: fromclientconfigformatcloudsourcedataframegoogle
1条回答
网友
1楼 · 发布于 2024-04-23 10:26:09

明白了。在浏览了谷歌的文档之后,我忘了写:

load_config = bigquery.LoadJobConfig()
load_config.schema = SCHEMA

哦。从未从BigQuery包加载config dict。在

相关问题 更多 >