Skip to content

bigquery-how-to-delete-partation

Published: at 下午10:30

bigquery-how-to-delete-partation

#!/bin/bash

# 设置开始日期和结束日期
start_date="20230111"
end_date="20230331"

# 循环删除表
current_date=$start_date

while [ "$current_date" -le "$end_date" ]; do
    current_hh="00"
    while [ "$current_hh" -le "23" ]; do
        # 构建表名
        table_name="YOUR_DATASET.YOUR_TABLE\$${current_date}${current_hh}"

        echo 要刪除table_name: $table_name
        # 执行删除命令
        bq rm -f --table "$table_name"
        echo 已刪除table_name: $table_name

        # 增加小时
        current_hh=$(printf "%02d" $((10#$current_hh + 1)))
    done

    # 增加日期
    current_date=$(date -j -v +1d -f "%Y%m%d" "$current_date" "+%Y%m%d")
done