#!/bin/bash
#需要指定hive中的庫名
#set -x
set -e
DB=$1
if [ -z $1 ];then
echo “Usage:$0 DbName”
exit 1
fi
#註釋掉cron對應的計劃任務
row=$(sed -n '/sjob_exec.sh/=' /etc/crontab)
sed -i "$row s/^/#/" /etc/crontab
#獲取hive表定義
ret=$(sudo -u hdfs hive -e "use ${DB};show tables;"|grep -v _tmp|grep -v importinfo)
for tem in $ret;
do
echo ${tem}
sudo -u hdfs hive -e "use ${DB};drop table ${tem}_tmp"
sudo -u hdfs hive -e "use ${DB};create table ${tem}_tmp_1 as select * from ${tem}"
sudo -u hdfs hive -e "use ${DB};alter table ${tem} rename to ${tem}_tmp"
sudo -u hdfs hive -e "use ${DB};alter table ${tem}_tmp_1 rename to ${tem}"
done
impala-shell -q 'invalidate metadata' -i hslave1
#恢復對應的cron任務
row=$(sed -n '/sjob_exec.sh/=' /etc/crontab)
sed -i "$row s/#//" /etc/crontab
通過創建臨時表合併某一個庫的hive小文件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.