How to check whether a partition exists with hive

拜拜、爱过 提交于 2019-12-24 09:05:57

问题


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:


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


来源:https://stackoverflow.com/questions/50172422/how-to-check-whether-a-partition-exists-with-hive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!