首页 > 解决方案 > 如何使用 hive 检查分区是否存在

问题描述

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

标签: hivehiveqlhive-partitions

解决方案


使用外壳:

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

推荐阅读