我需要在Bigquery中创建一个按特定字段划分的表。我注意到这只能通过API Rest使用。是否可以通过Python API做到这一点?
有帮助吗?
答案 0 :(得分:1)
我的猜测是文档还没有更新(无论如何,滚动http请求和调用API都很难),因为如果您查看BigQuery Python客户端库的code ,它的确确实支持在创建分区表时指定字段:
答案 1 :(得分:1)
扩展Graham Polley的答案:您可以通过设置time_partitioning
属性来进行设置。
类似这样的东西:
import google.cloud.bigquery as bq
bq_client = bq.Client()
dataset = bq_client.dataset('dataset_name')
table = dataset.table('table_name')
table = bq.Table(table, schema=[
bq.SchemaField('timestamp', 'TIMESTAMP', 'REQUIRED'),
bq.SchemaField('col_name', 'STRING', 'REQUIRED')])
table.time_partitioning = bq.TimePartitioning(field='timestamp')
bq_client.create_table(table)