hbase按照時間戳刪除記錄


1、按照時間戳范圍查詢記錄

echo "scan 'event_log', { COLUMN => 'cf:sid', TIMERANGE => [1466265600272, 1471622400481]} " |  hbase shell > ./record.txt

其中這里的cf:sid和key一致, 時間戳范圍需要按照時間自己轉換:

#current=`date "+%Y-%m-%d %H:%M:%S"`     #獲取當前時間,例:2015-03-11 12:33:41
current=“2015-03-11 12:33:41”
timeStamp=`date -d "$current" +%s`      #將current轉換為時間戳,精確到秒
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) #將current轉換為時間戳,精確到毫秒
echo $currentTimeStamp

2、通過shell命令提取record.txt中的sid字段,並拼成hbase刪除行命令

cat record.txt|awk '{print "deleteall '\''event_log'\''", ",", "'\''"$1"'\''"}' > del.sh

3、生成hbase刪除腳本

在del.sh頭尾分別加上:

#!/bin/sh 
exec hbase shell <<EOF 
EOF 

4、執行刪除腳本

sh del.sh


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM