now=`date +%Y%m%d`
# now=20201205
while true
do
partitions=$(hive -e "show partitions dm_tag.dwl_pubsentiment_st_day_zp" | grep -v WARN)
if [[ $partitions == *$now* ]]
then
echo "包含"
last_ddl_all=$(echo `hive -e "desc formatted dm_tag.dwl_pubsentiment_st_day_zp partition(tag_biz_time=$now)"` | grep -Eo 'transient_lastDdlTime [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
last_ddl=${last_ddl_all:22}
mx_tm=$(hive -e "select max(tag_updated) as max_tm from dm_tag.dwl_pubsentiment_st_day_zp where tag_biz_time=$now" | grep -v WARN)
if [ $last_ddl -gt $mx_tm ]
then
echo 'over'
break
else
sleep 1200
fi
else
sleep 3600
fi
done
假设上游表有分区,有数据更新时间的时间戳.通过desc formatted 表分区的详细信息中的transient_lastDdlTime 的值,一般数据跑完之后,它的值比表分区中最大的数据更新时间戳的值略大
判断上游任务是否完成.1.通过判断上游是否有分区,2判断transient_lastDdlTime是否大于表分区中最大的时间戳值.同时满足说明上游任务完成.没有则休眠
简易方式
检查上游是否存在分区,不存在等待一个小时,存在根据经验或者上游任务的平均时间,给出一个等待时间