0

I am looking to include a where clause to an existing query to exclude data in the BigQuery streaming buffer.

To do this I would like to get the Partition column name so I can add

WHERE partition_column IS NOT NULL;

to my existing query.

I have been looking at the CLI and the get_table method however that just returns the value of the column not the column name. I get the same when searching on .INFORMATION_SCHEMA.PARTITIONS this returns a field for partition_id but I would prefer the column name itself, is there away to get this ?

Additionally the table is setup with column based partitioning.

2
  • Why don't you use _PARTITIONTIME pseudo column to apply your filter? Commented Nov 10, 2021 at 20:18
  • @guillaumeblaquiere The _PARTITIONTIME column doesn't exist when using column based partitioning, you get the pseudo columns when using Partition by ingestion time at table creation. Commented Nov 11, 2021 at 9:37

1 Answer 1

2

Based on python BigQuery client documentation, use the attribute time_partitioning:

from google.cloud import bigquery
bq_table = client.get_table('my_partioned_table')
bq_table.time_partitioning # TimePartitioning(field='column_name',type_='DAY')
bq_table.time_partitioning.field # column_name

Small tips, if you don't know where to search, print the API repr:

bq_table.to_api_repr()
Sign up to request clarification or add additional context in comments.

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.