如何使用Hive检查分区是否存在 [英] How to check whether a partition exists with hive

查看:1909
本文介绍了如何使用Hive检查分区是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HiveQL脚本,可以基于hive表执行一些操作.但是在执行这些操作之前,我将检查所需的分区是否存在,如果不存在,则将终止脚本.那我该如何实现呢?

I have a HiveQL script that can do some operations based on a hive table. But before doing these operations, I will check whether the partition needed exists, and if not, I will terminate the script. So how can I achieve it?

推荐答案

使用shell:

table_name="schema.table"
partition_spec="key=value"

partition_exists=$(hive -e "show partitions $table_name" | grep "$partition_spec");

#check partition_exists
 if [ "$partition_exists" = "" ]; then echo not exists; else echo exists; fi

这篇关于如何使用Hive检查分区是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆