BigQuery-删除日期分割表的最佳方法

Ary*_*azz 5 google-bigquery google-cloud-platform

我有几个要删除的日期分片表,但每个表已经有100多个分片,因此不能手动删除它们。

我尝试使用通配符

DROP TABLE my_dataset.my_table_*;
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用。

我终于使用了python API:

for table_id in tables:
    table_ref = client.dataset(dataset_id).table(table_id)
    client.delete_table(table_ref)
Run Code Online (Sandbox Code Playgroud)

它可以工作,但是我需要使用要删除的表的名称来创建表数组。

有没有一种方法可以从用户界面中删除BigQuery中日期已划分的表的所有日期中的日期?

还是在用户界面中使用SQL命令?

还是在命令行中使用通配符?

谢谢

Tem*_*emu 4

And what about instead of creating the tables array (with the names of the tables) you use...

from google.cloud import bigquery
client = bigquery.Client()
dataset_ref = client.dataset('my_dataset')

tables = list(client.list_tables(dataset_ref))  # API request(s), now you have the list of tables in this dataset
queried_tables=[]
for table in tables:
    print(table.table_id)
    if table.table_id.startswith("your_favourite_prefix"): #will perform the action only if the table has the desired prefix
        queried_tables.append(table.table_id)

print(queried_tables) #the list of the desired tables names, now you can use your script to delete them all
Run Code Online (Sandbox Code Playgroud)