使用shell脚本删除hive外部表hdfs元数据

1、原hdfs上文件目录
在这里插入图片描述
2、编写shell脚本delete_external_partitiondata.sh

#! /bin/bash

#要求传入的数据格式为yyyyMMdd的两个开始和结束参数,如20210302 20210303

tableName=$1
partitionName=$2
start=$3
end=$4

#将输入的日期转为的时间戳格式
startDate=`date -d "${start}" +%s`
endDate=`date -d "${end}" +%s`

#计算两个时间戳的差值除于每天86400s即为天数差
stampDiff=`expr $endDate - $startDate`
dayDiff=`expr $stampDiff / 86400`

for ((i=0;i<=$dayDiff;i++))
 do
   process_date=`date -d "${start} $i day" +'%Y%m%d'`

   info=`hive -e "desc formatted $tableName"`
   info=(`echo $info| sed -r "s/.*?(hdfs:.*?) Table.*?/\1/g"`)
   info=${info[0]}

   hdfs dfs -rm -r "$info/$partitionName=$process_date"
 done

3、执行脚本

[root@sgh1vhdp01 shelltest]# ./clearpartitiondata.sh clearpartitiondata_test dt 20210301 20210302

4、删除后hdfs文件目录
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值