获取hive表的最近一个分区
#!/bin/sh
table1='db_name.tbl_name'
v_partition=`hive -e "show partitions $table1" | grep "pt=*" | sort | tail -n 1`
last_partition=${v_partition:10:8}
echo ${last_partition}
判断hive表的分区是否存在
#!/bin/sh
incDay=`date -d "1 day ago" +%Y%m%d`
table1='db_name.tbl_name'
pt=$incDay
temp=`hive -e "show partitions $table1"`
echo $temp|grep -wq "$pt"
if [ $? -eq 0 ];then
echo "true"
else
echo "false"
fi
该脚本用于获取Hive表的最新分区并检查指定日期的分区是否存在。首先,它展示表的所有分区,过滤出以pt=开头的行,排序后取最后一个作为最新的分区。然后,脚本计算前一天的日期并检查这个日期对应的分区是否存在于表中。

756

被折叠的 条评论
为什么被折叠?



