2

I need to create a table in Bigquery partitioned by a specific field. I have noticed that this is only available via API Rest. Is there a way to do this via Python API?

Any help?

1

2 Answers 2

2

My guess is that the docs just haven't been updated yet (not that rolling a http request and calling the API would be hard anyway), because if you look at the code for the BigQuery Python client library, it does indeed appear to support specifying the field when creating a partitioned table:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

2

Expanding on Graham Polley's answer: You can set this by setting the time_partitioning property.

Something like this:

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.