How to check whether a partition exists with hive

2019-08-04 11:52发布

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?

1条回答
姐就是有狂的资本
2楼-- · 2019-08-04 12:27

Using 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
查看更多
登录 后发表回答