使用 Python 和 API 创建 Bigquery 分区表

Posted

技术标签:

【中文标题】使用 Python 和 API 创建 Bigquery 分区表【英文标题】:Create Bigquery partitioned table using Python and API 【发布时间】:2018-04-27 11:18:47 【问题描述】:

我想使用 client.create_table() 从 Python 脚本在 BigQuery 中创建分区表,但收到错误消息

TypeError: create_table() got an unexpected keyword argument 'time_partitioning'`

如果有人能告诉我哪里出错了,那就太好了。

这是我正在使用的代码:

client = bigquery.Client.from_service_account_json('path/to/key')
...
data_ref = bigquery.DatasetReference(PROJECT_ID, DATASET_ID)
table_ref = bigquery.TableReference(data_ref, new_TABLE_ID)
table = bigquery.Table(table_ref, schema = SCHEMA) 
new_table = client.create_table(table, time_partitioning = True)

This is some documentation I used

【问题讨论】:

是否有理由不使用 CREATE TABLE 语句?我觉得那样会更容易。请参阅DDL documentation。 【参考方案1】:

仅供参考

client = bigquery.Client.from_service_account_json('path/to/key')
... 
data_ref = bigquery.DatasetReference(PROJECT_ID, DATASET_ID)
table_ref = bigquery.TableReference(data_ref, new_TABLE_ID)
table = bigquery.Table(table_ref, schema = SCHEMA)
table.partitioning_type = 'DAY' 
client.create_table(table)

【讨论】:

以上是关于使用 Python 和 API 创建 Bigquery 分区表的主要内容,如果未能解决你的问题,请参考以下文章

使用 Python 和 API 创建 Bigquery 分区表

仅使用 Google App Engine、webapp2 和 Python 创建 API?

如何使用python修复在bigquery中上传csv文件

通过 C API 从字符串创建和调用 python 函数

这是使用 API 在 Python 中为 Braintree 创建订阅的正确方法吗

如何在 Django 和 Python 中使用 JWT(JSON Web 令牌)来创建用于注册和登录的 REST API