hbase(main):001:0> help HBase Shell, version 2.1.6, rba26a3e1fd5bda8a84f99111d9471f62bb29ed1d, Mon Aug 26 20:40:38 CST 2019 Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command. Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.
COMMAND GROUPS: Group name: general Commands: processlist, status, table_help, version, whoami ...
如果想退出 Shell,可以通过键入 exit 退出:
hbase(main):002:0> exit
2. 常规命令
在 Hbase 中,有如下常规命令:
status
version
whoami
2.1 status
可以使用 status 命令展示 HBase 集群的系统状态的详细,例如服务器数量:
hbase(main):001:0> status 1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load Took 0.3686 seconds
我们还可以传递特定参数,具体取决于我们想了解系统的哪些详细状态。参数可以为 summary,simple,detailed 或 replication。默认不填为 summary。下面我们展示了如何将不同的参数传递给 status 命令:
hbase> status hbase> status 'simple' hbase> status 'summary' hbase> status 'detailed' hbase> status 'replication' hbase> status 'replication', 'source' hbase> status 'replication', 'sink'
put 't1', 'r1', 'f1:c1', 'this is first value' put 'ns1:t1', 'r1', 'f1:c1', 'this is first value of ns1'
4.2 Get
可以使用 get 命令获取 HBase 表的一行或者一个单元的内容:
hbase> get 'ns1:t1', 'r1' hbase> get 't1', 'r1' hbase> get 't1', 'r1', {TIMERANGE => [ts1, ts2]} hbase> get 't1', 'r1', {COLUMN => 'c1'} hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']} hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1} hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4} hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4} hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"} hbase> get 't1', 'r1', 'c1' hbase> get 't1', 'r1', 'c1', 'c2' hbase> get 't1', 'r1', ['c1', 'c2'] hbase> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}} hbase> get 't1', 'r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']} hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE'} hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
例如,使用如下命令可以获取表 t1 的一条记录:
hbase(main):028:0> get 'ns1:t1', 'r1' COLUMN CELL f1:c1 timestamp=1573986505024, value=this is third value of ns1 1 row(s) Took 0.0299 seconds
Get 也可以支持获取多个版本的数据,但是需要修改表的 VERSIONS 属性以支持多版本:
hbase(main):019:0> alter 'ns1:t1', NAME => 'f1', VERSIONS => 3 Updating all regions with the new schema... 1/1 regions updated. Done. Took 1.8057 seconds
hbase(main):027:0> get 'ns1:t1', 'r1', {COLUMN => 'f1:c1', VERSIONS => 3} COLUMN CELL f1:c1 timestamp=1573986505024, value=this is third value of ns1 f1:c1 timestamp=1573986499590, value=this is second value of ns1 f1:c1 timestamp=1573986493844, value=this is first value of ns1 1 row(s) Took 0.0070 seconds
hbase(main):042:0> scan 'ns1:t1' ROW COLUMN+CELL r1 column=f1:c1, timestamp=1573994164276, value=this is first value of r1 r2 column=f1:c1, timestamp=1573994095092, value=this is first value of r2 r3 column=f1:c1, timestamp=1573994102776, value=this is first value of r3 r4 column=f1:c1, timestamp=1573994109851, value=this is first value of r4 r5 column=f1:c1, timestamp=1573994116959, value=this is first value of r5 r6 column=f1:c1, timestamp=1573994123621, value=this is first value of r6 r7 column=f1:c1, timestamp=1573994130600, value=this is first value of r7 r8 column=f1:c1, timestamp=1573994138110, value=this is first value of r8 8 row(s) Took 0.0137 seconds
我们也可以通过指定时间区间获取某个时刻的数据:
hbase(main):043:0> scan 'ns1:t1', {TIMERANGE => [1573994102776, 1573994130600]} ROW COLUMN+CELL r3 column=f1:c1, timestamp=1573994102776, value=this is first value of r3 r4 column=f1:c1, timestamp=1573994109851, value=this is first value of r4 r5 column=f1:c1, timestamp=1573994116959, value=this is first value of r5 r6 column=f1:c1, timestamp=1573994123621, value=this is first value of r6 4 row(s) Took 0.0786 seconds
我们也可以从 r6 行键开始获取 2 条记录:
hbase(main):002:0> scan 'ns1:t1', {COLUMNS => 'f1:c1', LIMIT => 2, STARTROW => 'r6'} ROW COLUMN+CELL r6 column=f1:c1, timestamp=1573994123621, value=this is first value of r6 r7 column=f1:c1, timestamp=1573994130600, value=this is first value of r7 2 row(s) Took 0.4751 seconds
4.4 Count
可以使用 count 命令统计表的行数:
hbase(main):005:0> count 'ns1:t1' 8 row(s) Took 0.0726 seconds => 8
hbase(main):007:0> count 'ns1:t1', INTERVAL => 2 Current count: 2, row: r2 Current count: 4, row: r4 Current count: 6, row: r6 Current count: 8, row: r8 8 row(s) Took 0.0200 seconds => 8
4.5 Append
可以使用 append 命令向指定的单元上在原先值上追加新值:
hbase> append 't1', 'r1', 'c1', 'value'
例如,使用如下命令在原先的值后面追加, append a new value:
hbase(main):047:0> get 'ns1:t1', 'r1' COLUMN CELL f1:c1 timestamp=1573994164276, value=this is first value of r1 1 row(s) Took 0.0475 seconds hbase(main):049:0> append 'ns1:t1', 'r1', 'f1:c1', ', append a new value' CURRENT VALUE = this is first value of r1, append a new value Took 0.0119 seconds hbase(main):050:0> get 'ns1:t1', 'r1' COLUMN CELL f1:c1 timestamp=1573996248316, value=this is first value of r1, append a new value 1 row(s) Took 0.0171 seconds