gpt4 book ai didi

google-cloud-platform - BigQuery - 删除日期分片表的最佳方式

转载 作者:行者123 更新时间:2023-12-03 22:52:31 24 4
gpt4 key购买 nike

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

我试过使用通配符

DROP TABLE my_dataset.my_table_*;

但它似乎不起作用。

我终于使用了python API:
for table_id in tables:
table_ref = client.dataset(dataset_id).table(table_id)
client.delete_table(table_ref)

它有效,但我需要使用我想要删除的表的名称创建表数组。

有没有办法从 UI 中删除 BigQuery 中日期分片表的所有日期分片?

或者在 UI 中使用 SQL 命令?

或者使用带有通配符的命令行?

谢谢

最佳答案

而不是创建您使用的表数组(带有表的名称)呢?

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

关于google-cloud-platform - BigQuery - 删除日期分片表的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52151185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com