-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhive-fix_dup_port_in_location.sh
executable file
·38 lines (23 loc) · 1.21 KB
/
hive-fix_dup_port_in_location.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
#fix duplicate port numbers in hdfs storage location for hive tables and underlying partitions
hive_host="ss-cdh-8:10000"
hive_command="beeline --color=false --showHeader=false --fastConnect=true --verbose=false --showWarnings=false --showNestedErrs=false --silent=true --outputformat=tsv -u jdbc:hive2://$hive_host/ -e "
for table in $(impala-shell -B -q 'show tables' 2>/dev/null);do
echo "updating table $table"
location=$($hive_command "describe formatted $table"|grep ^\'Location:|awk -F'\t' '{print $2}'|tr -d \')
newlocation=$(echo $location|sed 's/8020:8020/8020/g')
if [ ! -z "$newlocation" ];then
$hive_command "alter table $table set location '$newlocation'"
echo "updated table $table"
#fix individual partisions as well
partitions=$($hive_command "show partitions $table;" 2>/dev/null|tr -d \')
if [ ! -z "$partitions" ];then
echo "updating partitions for table $table"
for part in $partitions;do
$hive_command "alter table $table partition ($(echo "$part"|tr '/' ',')) set location '${newlocation}/$part'";
done
echo "updated partitions for table $table"
fi
fi
done
wait