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