如何使用配置单元检查分区是否存在

f45qwnt8  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(299)

我有一个hiveql脚本,它可以基于配置单元表执行一些操作。但是在执行这些操作之前,我将检查所需的分区是否存在,如果不存在,我将终止脚本。那我怎么才能做到呢?

amrnrhlw

amrnrhlw1#

使用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

相关问题