-
Notifications
You must be signed in to change notification settings - Fork 0
/
HbaseDeleteShell.sh
32 lines (26 loc) · 1.05 KB
/
HbaseDeleteShell.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
# HbaseTimeRangeDelete
#Delete data based on time range in hbase using hbase shell
#Date calculations based on requirements
DATE_LOG=`cat datelog.txt`
hbase_endDate=$(date -d "$DATE_LOG -6 day" +"%Y-%m-%d %H:%M:%S.%3N")
END_EPOCH_TIME=$(date -d "$hbase_endDate" '+%s%3N')
#Create hbase scan query from date and fetch the rowkey
HBASE_QUERY="scan "\'${hbaseTableName}\'",{COLUMNS => ['api:columFamily'], TIMERANGE => [0,${END_EPOCH_TIME}] }"
GetRowKey=$(echo ${HBASE_QUERY} | hbase shell -n | awk '{print $1}')
#Create rowkey as list of string
GetRowKeyList=$(echo $GetRowKey | sed 's/ /,/g')
GetRowKeyList=$(echo ${GetRowKeyList} | sed -e "s/^/'/" -e "s/\$/'/" -e "s/,/','/g")
#Creat deleteall command for each rowkey
deleteallCommand=""
for rowkey in $(echo $GetRowKeyList | tr ',' '\n')
do
deleteCommand=`echo "deleteall "\'${hbaseTableName}\'",${rowkey}"`
deleteallCommand+="$deleteCommand "$'\n'
done
#Submit the deleteall commands to hbase shell
fnbulkdelete(){
exec hbase shell -n <<EOF
$deleteallCommand
EOF
}
fnbulkdelete