Bigquery Python API按特定字段创建分区表

时间:2018-07-11 10:33:19

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

我需要在Bigquery中创建一个按特定字段划分的表。我注意到这只能通过API Rest使用。是否可以通过Python API做到这一点?

有帮助吗?

2 个答案:

答案 0 :(得分:1)

我的猜测是文档还没有更新(无论如何,滚动http请求和调用API都很难),因为如果您查看BigQuery Python客户端库的code ,它的确确实支持在创建分区表时指定字段:

enter image description here

答案 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)