hive - 如何使用 hive 检查分区是否存在
问题描述
我有一个 HiveQL 脚本,它可以基于 hive 表执行一些操作。但在做这些操作之前,我会检查需要的分区是否存在,如果不存在,我会终止脚本。那么我该如何实现呢?
解决方案
使用外壳:
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
推荐阅读
- r - st_join 错误 - 在下一个故障排除步骤中需要帮助
- excel - Excel - 源单元格为计数的标准偏差
- excel - 我需要一个 VBA 将行中的唯一值添加到列中
- regex - 如何在 Common Lisp 中使用正则表达式来获取字符串中的所有内容,直到最后一次出现“/”?
- python - 如何将值存储在循环内的变量中并在其他循环中运行
- java - 使用 ND4J,将四维字节数组转换为 INDArray
- php - 使用codeigniter在mysql中插入url参数
- meshroom - Meshroom 命令行界面 (CLI)
- c# - “@Price”附近的语法不正确
- javascript - 有人能解释一下这个简单的 javascript (ES6) 行对箭头函数有什么作用吗?