#!bin/bash
set -x
#定义表数组
tablearr=(aaa)
#tablearr=(dws.ccc)
for t in ${tablearr[@]}
do
#查询hive表分区
str="show partitions ads."$t";"
source_num=$(hive -e "$str" | awk -F'[=/]' '{print $2}')
#查询doris表分区
str2="select distinct concat_ws('=','fileid',check_time) from dw."$t";"
target_num=$(mysql -uroot -pbbb -P9030 -h123.168.66.266 -e "$str2" | awk -F '=' 'NR>1 {print $2}')
#echo "doris切割结果:$target_num"
#循环创建doris分区,如果有分区则跳过,如果没有分区则创建分区
target_arr=()
source_arr=()
exist_arr=()
for i in $target_num
do
target_arr+=($i)
done
for j in $source_num
do
source_arr+=($j)
done
for i in ${!source_arr[@]}
do
for j in ${!target_arr[@]}
do
if [[ ${target_arr[$i]} = ${source_arr[$j]} ]];then
echo 'doris表'$t'分区'${source_arr[$i]}'已经存在,
doris批量创建分区,shell脚本
于 2024-01-30 16:44:21 首次发布