hbase shell 常用命令

来源:互联网 发布:怎样网络上发布小说 编辑:程序博客网 时间:2024/06/02 08:53
hbase Shell 保存历史命令
可以在你自己的Home目录下创建一个.irbrc文件. 在这个文件里加入自定义的命令。
有一个有用的命令就是记录命令历史,这样你就可以把你的命令保存起来。

$ more .irbrcrequire 'irb/ext/save-history'IRB.conf[:SAVE_HISTORY] = 100IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"

LOG 时间转换
可以将日期'08/08/16 20:56:29'从hbase log 转换成一个 timestamp, 操作如下:

hbase(main):021:0> import java.text.SimpleDateFormathbase(main):022:0> import java.text.ParsePositionhbase(main):023:0> SimpleDateFormat.new("yy/MM/dd HH:mm:ss").parse("14/12/04 00:00:00", ParsePosition.new(0)).getTime() => 1218920189000

也可以逆过来操作。
hbase(main):021:0> import java.util.Datehbase(main):022:0> Date.new(1425629580841).toString() => "Sat Aug 16 20:56:29 UTC 2008"hbase(main):022:0> Date.new().getTime() => 1417675776783
                   
2.重启当前节点:
hbase-daemon.sh start regionserver

hbase shell 常用命令:

获取时间戳:Date.new().getTime()

hbase(main):001:0> get "UrlLink","1","document"

查询一行 一列
get "UrlLink","1","document:column2"

更新一条记录
将scutshuxue的年龄改成99
hbase(main):004:0>put 'UrlLink','1','ocument:column4' ,'99'

hbase 查询时间范围内的数据
hbase>scan 'UrlLink',{TIMERANGE=>[1425279600000,1425312000000]}

hbase查询版本大于2的数据:
hbase>scan 'UrlLink',{VERSIONS=>2}

HBase如何存取多个版本的值
get有用法如下:
hbase> get 'URLLINK', 'http://guba.sina.com.cn/?s=thread&tid=35262&bid=14806'hbase> get 'URLLINK', 'http://zzwb.zynews.com/html/2014-12/04/content_619217.htm', {TIMERANGE => [ts1, ts2]}hbase>scan 'URLLINK',{TIMERANGE=>[1417968000000,1418047320000]}hbase> get ‘t1′, ‘r1′, {COLUMN => 'cf:c1'}                 #查询具体某一列。hbase(main):027:0> get 'UrlLink12', 'http://www.cjk3d.net/viewnews-753975', {COLUMN => 'document:content',TIMESTAMP => 1407722201150}hbase> get ‘t1′, ‘r1′, {COLUMN => ['cf:c1', 'cf:c2', 'cf:c3']}hbase> get ‘t1′, ‘r1′, {COLUMN => 'cf:c1', TIMESTAMP => ts1}hbase> get ‘t1′, ‘r1′, {COLUMN => 'cf:c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}hbase> get ‘t1′, ‘r1′, {COLUMN => 'cf:c1', TIMESTAMP => ts1, VERSIONS => 4}hbase> get ‘t1′, ‘r1′, ‘c1′hbase> get ‘t1′, ‘r1′, ‘c1′, ‘c2′hbase> get ‘t1′, ‘r1′, ['c1', 'c2'] 


0 0