#!/bin/bash
#修复hive外表分区
echo -e $(date +%F%n%T)' input parameters:table_names:'$1' and table names:'$2 ' of partitions'
#如果第一个参数不为空,用参数,否则用默认值.如果第一个参数是all,则会把库里面所有表都遍历一遍
if [ ! -n "$1" ] ;then
table_names='wechat_f_imspcheckinuserinfo,wechat_f_imspuseraction,wechat_f_trfgroupuser,brtl_bc_rtl_cvr_trx_evt' #默认修复的表
else
table_names=$1
fi
#如果第二个参数不为空,用参数,否则用默认值
if [ ! -n "$2" ] ;then
database='hl_ops' #默认修复的数据库
else
database=$2
fi
echo -e $(date +%F%n%T)' create database:'$database' and table names:'$table_names ' of partitions'
if [ $1 == "all" ] ;then
echo -e $(date +%F%n%T) "show tables from "$database";"
table_names_array=$(hive -e "show tables from "$database";")
else
table_names_array=${table_names//,/ } #这里是将var中的,替换为空格
fi
echo $table_names_array
for table_name in $table_names_array
do
echo -e '\n\n'
echo -e $(date +%F%n%T)' create '$database'.'$table_name ' of partitions'
echo -e 'MSCK REPAIR TABLE '$database'.'$table_name
hive -e 'MSCK REPAIR TABLE '$database'.'$table_name
done
```shell
网友评论