etl实现上下游依赖的一种脚本

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是否大于表分区中最大的时间戳值.同时满足说明上游任务完成.没有则休眠

简易方式
检查上游是否存在分区,不存在等待一个小时,存在根据经验或者上游任务的平均时间,给出一个等待时间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值