Hive批量删除表分区

Hive批量删除表分区

shell脚本


#!/usr/bin/bash

#获取当前脚本所在路径
cur_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd ${cur_dir}

#导出所有hive数据库名
hive -e "show databases;" > ${cur_dir}/all_database.txt

#获取以src开头的库名
cat all_database.txt | awk '{print $2}' | awk '/^src_.*/{print}' > ${cur_dir}/src_database.txt

for database in `cat ${cur_dir}/src_database.txt`
do
    #获取表名
    hive -e "use ${database};show tables;" > ${cur_dir}/${database}_tbs.txt
	
	for table in `tail -n +3 ${cur_dir}/${database}_tbs.txt | awk '/[a-zA-Z]/{print $2}'`
	do
		echo -e "\e[36m -----${database}.${table}------ \e[0m"
		#获取表分区
		hive -e "show partitions ${database}.${table}" > ${cur_dir}/${database}.${table}_pts.txt
		#循环表的分区
		for partition in `tail -n +3 ${cur_dir}/${database}.${table}_pts.txt | awk '/[a-zA-Z0-9]/{print $2}' | awk '/^batch_no=202005.*/{print}'`
		do
			echo -e "\e[36m-----${partition}------\e[0m"
			#删除表的分区
			hive -e "alter table  ${database}.${table} drop if exists partition (${partition});"
		done
	done
done

HDFS清理回收站

hdfs dfs -du -h /user/hive/
hdfs dfs -rm -r -skipTrash /user/hive/.Trash
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值