For people like myself who clicked for the title BigQuery (BQ) - Drop Partition but are looking to do it with api.
You drop a partition the same way you delete a table only adding ${partrition}
to the end, i.e. my.table.id$20230101
. (api doc for deleting a table)
example using python:
from google.cloud import bigquery
client.delete_table('my.table.id$20230101')
and a if anyone else wants to delete daily partritions
from google.cloud import bigquery
from datetime import date
def delete_day_partition(table_id: str, day: date):
"""
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/delete
https://mcmap.net/q/2029565/-is-there-a-way-of-deleting-old-partitions-in-a-partitioned-table-using-bigquery-api
"""
client = bigquery.Client()
day = day.strftime('%Y%m%d') # date() -> 'YYYYMMDD'
partition = f'{table_id}${day}'
client.delete_table(partition)
delete_day_partition('my.table.id', date(2023, 1, 1))