【问题标题】:BigQuery - Best way to DROP date-sharded tablesBigQuery - 删除日期分片表的最佳方法
【发布时间】:2019-02-08 14:17:31
【问题描述】:

我有几个日期分片表要删除,但每个表已经有超过 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 命令?

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

谢谢

【问题讨论】:

    标签: google-cloud-platform google-bigquery


    【解决方案1】:

    没有内置的方法可以删除共享一个公共前缀的所有表。您使用 Python 库将它们全部删除的方法是一个合理的选择,或者您可以通过调用 bq rm dataset.table_name 的循环从命令行执行相同的操作。

    【讨论】:

      【解决方案2】:

      你使用的不是创建表数组(带有表的名称)......

      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
      

      【讨论】:

      • 太棒了@Termu。谢谢
      • 如果这对你有价值,如果你在某个时候接受我的回答,我将不胜感激:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-14
      • 2021-07-24
      • 2021-08-10
      • 1970-01-01
      • 2016-08-27
      • 1970-01-01
      • 2019-11-25
      相关资源
      最近更新 更多