HBase Shell基本使用总结

创建一个表

hbase(main):002:0> create 'member', 'cf_tmp', 'address', 'info'

 

查看所有表清单

hbase(main):003:0> list
TABLE
member
1 row(s) in 0.0210 seconds

  

查看表描述

hbase(main):004:0> describe 'member'
Table member is ENABLED                                                                
member                                                                                                                                                                  
COLUMN FAMILIES DESCRIPTION                                                                                                                                             
    {
		NAME => 'address', 
		BLOOMFILTER => 'ROW', 
		VERSIONS => '1', 
		IN_MEMORY => 'false', 
		KEEP_DELETED_CELLS => 'FALSE', 
		DATA_BLOCK_ENCODING => 'NONE', 
		TTL => 'FOREVER', 
		COMPRESSION => 'NONE', 
		MIN_VERSIONS => '0', 
		BLOCKCACHE => 'true', 
		BLOCKSIZE => '65536', 
		REPLICATION_SCOPE => '0'
	}                                                              

	{
		NAME => 'cf_tmp', 
		BLOOMFILTER => 'ROW', 
		VERSIONS => '1', 
		IN_MEMORY => 'false', 
		KEEP_DELETED_CELLS => 'FALSE', 
		DATA_BLOCK_ENCODING => 'NONE', 
		TTL => 'FOREVER', 
		COMPRESSION => 'NONE', 
		MIN_VERSIONS => '0', 
		BLOCKCACHE => 'true', 
		BLOCKSIZE => '65536', 
		REPLICATION_SCOPE => '0'
	
	}
	
	{
		NAME => 'info', 
		BLOOMFILTER => 'ROW', 
		VERSIONS => '1', 
		IN_MEMORY => 'false', 
		KEEP_DELETED_CELLS => 'FALSE', 
		DATA_BLOCK_ENCODING => 'NONE', 
		TTL => 'FOREVER', 
		COMPRESSION => 'NONE', 
		MIN_VERSIONS => '0', 
		BLOCKCACHE => 'true', 
		BLOCKSIZE => '65536', 
		REPLICATION_SCOPE => '0'
	}                                                                 
3 row(s) in 0.0330 seconds

 

浏览表中的数据

hbase(main):005:0> scan 'member'
ROW                                         COLUMN+CELL                                                                                                                 
0 row(s) in 0.0580 seconds

  

删除一个列簇

hbase(main):006:0> disable 'member'
0 row(s) in 1.2720 seconds

hbase(main):007:0> is_disabled 'member'
true                                                                                                                              
0 row(s) in 0.0110 seconds

hbase(main):009:0> alter 'member', {NAME=>'cf_tmp', METHOD=>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.1620 seconds

hbase(main):010:0> enable 'member'
0 row(s) in 0.4120 seconds

 

插入几条数据

hbase(main):012:0> put 'member', '43010319820725XXXX', 'info:name', 'zhoulin'
0 row(s) in 0.0690 seconds

hbase(main):013:0> put 'member', '43010319820725XXXX', 'info:age', '35'
0 row(s) in 0.0260 seconds

hbase(main):014:0> put 'member', '43010319820725XXXX', 'info:birthday', '1982-07-25'
0 row(s) in 0.0190 seconds

hbase(main):015:0> put 'member', '43010319820725XXXX', 'info:company', 'asiainfo'
0 row(s) in 0.0110 seconds

hbase(main):016:0> put 'member', '43010319820725XXXX', 'address:contry', 'china'
0 row(s) in 0.0220 seconds

hbase(main):017:0> put 'member', '43010319820725XXXX', 'address:province', 'hunan'
0 row(s) in 0.0140 seconds

hbase(main):018:0> put 'member', '43010319820725XXXX', 'address:city', 'changsha'
0 row(s) in 0.0440 seconds

hbase(main):019:0> scan 'member'
ROW                         COLUMN+CELL                                                                                                                 
 43010319820725XXXX         column=address:city,     timestamp=1501569028721, value=changsha
 43010319820725XXXX         column=address:contry,   timestamp=1501569027675, value=china
 43010319820725XXXX         column=address:province, timestamp=1501569027715, value=hunan
 43010319820725XXXX         column=info:age,         timestamp=1501569027579, value=35
 43010319820725XXXX         column=info:birthday,    timestamp=1501569027617, value=1982-07-25
 43010319820725XXXX         column=info:company,     timestamp=1501569027640, value=asiainfo
 43010319820725XXXX         column=info:name,        timestamp=1501569018899, value=zhoulin
1 row(s) in 0.0170 seconds

 

获取数据

// 获取 指定ROWKEY的所有数据
hbase(main):020:0> get 'member', '43010319820725XXXX'
COLUMN                                      CELL
 address:city                               timestamp=1501569028721, value=changsha
 address:contry                             timestamp=1501569027675, value=china
 address:province                           timestamp=1501569027715, value=hunan
 info:age                                   timestamp=1501569027579, value=35
 info:birthday                              timestamp=1501569027617, value=1982-07-25
 info:company                               timestamp=1501569027640, value=asiainfo
 info:name                                  timestamp=1501569018899, value=zhoulin
7 row(s) in 0.0370 seconds

// 获取 指定ROWKEY、指定列簇的所有数据
hbase(main):031:0> get 'member', '43010319820725XXXX', 'info'
COLUMN                                      CELL
 info:age                                   timestamp=1501569027579, value=35
 info:birthday                              timestamp=1501569027617, value=1982-07-25
 info:company                               timestamp=1501569027640, value=asiainfo
 info:name                                  timestamp=1501569018899, value=zhoulin
4 row(s) in 0.0300 seconds

// 获取 指定ROWKEY、指定列的数据
hbase(main):032:0> get 'member', '43010319820725XXXX', 'info:age'
COLUMN                                      CELL
 info:age                                   timestamp=1501569027579, value=35
1 row(s) in 0.0350 seconds

// 获取 指定列簇、指定列,指定时间戳的数据
hbase(main):034:0> get 'member', '43010319820725XXXX', {COLUMN=>'info:age', TIMESTAMP=>1501569027579}
COLUMN                                      CELL
 info:age                                   timestamp=1501569027579, value=35
1 row(s) in 0.0160 seconds

 

更新一条记录

hbase(main):001:0> put 'member', '43010319820725XXXX', 'info:age', '30'
0 row(s) in 0.4880 seconds

hbase(main):002:0> get 'member', '43010319820725XXXX'
COLUMN                                      CELL                                                                                                                        
 address:city                               timestamp=1501569028721, value=changsha                                                                                     
 address:contry                             timestamp=1501569027675, value=china                                                                                        
 address:province                           timestamp=1501569027715, value=hunan                                                                                        
 info:age                                   timestamp=1501570309732, value=30                                                                                           
 info:birthday                              timestamp=1501569027617, value=1982-07-25                                                                                   
 info:company                               timestamp=1501569027640, value=asiainfo                                                                                     
 info:name                                  timestamp=1501569018899, value=zhoulin                                                                                      
7 row(s) in 0.0490 seconds

 

查询表中有多少行

hbase(main):003:0> count 'member'
1 row(s) in 0.0400 seconds

 

删除整行

hbase(main):007:0> deleteall 'member', '43010319820725XXXX'
0 row(s) in 0.0590 seconds

hbase(main):008:0> scan 'member'
ROW                                         COLUMN+CELL                                                                                                                 
0 row(s) in 0.0140 seconds

 

删除字段

// 删除ROWKEY为 43010319820725XXXX 的 'info:age' 字段
hbase(main):017:0> delete 'member', '43010319820725XXXX', 'info:age'
0 row(s) in 0.0110 seconds

hbase(main):018:0> scan 'member'
ROW                                         COLUMN+CELL
 43010319820725XXXX                         column=address:city, timestamp=1501570611266, value=changsha
 43010319820725XXXX                         column=address:contry, timestamp=1501570610720, value=china
 43010319820725XXXX                         column=address:province, timestamp=1501570610742, value=hunan
 43010319820725XXXX                         column=info:birthday, timestamp=1501570610574, value=1982-07-25
 43010319820725XXXX                         column=info:company, timestamp=1501570610611, value=asiainfo
 43010319820725XXXX                         column=info:name, timestamp=1501570610519, value=zhoulin
1 row(s) in 0.0200 seconds

  

增加字段

// 注:使用incr实现递增[不用预先增加字段salary]
hbase(main):019:0> incr 'member', '43010319820725XXXX', 'info:salary'
COUNTER VALUE = 1
0 row(s) in 0.0170 seconds

hbase(main):020:0> incr 'member', '43010319820725XXXX', 'info:salary'
COUNTER VALUE = 2
0 row(s) in 0.0220 seconds

hbase(main):021:0> incr 'member', '43010319820725XXXX', 'info:salary'
COUNTER VALUE = 3
0 row(s) in 0.0130 seconds

hbase(main):022:0> incr 'member', '43010319820725XXXX', 'info:salary', 10000
COUNTER VALUE = 10003
0 row(s) in 0.0140 seconds

hbase(main):023:0> incr 'member', '43010319820725XXXX', 'info:salary', 10000
COUNTER VALUE = 20003
0 row(s) in 0.0120 seconds

hbase(main):024:0> incr 'member', '43010319820725XXXX', 'info:salary', 10000
COUNTER VALUE = 30003
0 row(s) in 0.0070 seconds

hbase(main):025:0> incr 'member', '43010319820725XXXX', 'info:salary', 10000
COUNTER VALUE = 40003
0 row(s) in 0.0160 seconds

hbase(main):026:0> incr 'member', '43010319820725XXXX', 'info:salary', 10000
COUNTER VALUE = 50003
0 row(s) in 0.0070 seconds

// 获取计数器的值
hbase(main):027:0> get_counter 'member', '43010319820725XXXX', 'info:salary'
COUNTER VALUE = 50003

hbase(main):028:0> get 'member', '43010319820725XXXX', 'info:salary'
COLUMN            CELL
 info:salary      timestamp=1501571074556, value=\x00\x00\x00\x00\x00\x00\xC3S
1 row(s) in 0.0120 seconds

 

清空表

hbase(main):029:0> scan 'member'
ROW                                         COLUMN+CELL
 43010319820725XXXX                         column=address:city, timestamp=1501570611266, value=changsha
 43010319820725XXXX                         column=address:contry, timestamp=1501570610720, value=china
 43010319820725XXXX                         column=address:province, timestamp=1501570610742, value=hunan
 43010319820725XXXX                         column=info:birthday, timestamp=1501570610574, value=1982-07-25
 43010319820725XXXX                         column=info:company, timestamp=1501570610611, value=asiainfo
 43010319820725XXXX                         column=info:name, timestamp=1501570610519, value=zhoulin
 43010319820725XXXX                         column=info:salary, timestamp=1501571074556, value=\x00\x00\x00\x00\x00\x00\xC3S
1 row(s) in 0.0180 seconds

hbase(main):030:0> truncate 'member'
Truncating 'member' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 1.4890 seconds

hbase(main):031:0> scan 'member'
ROW                                         COLUMN+CELL                                                                                                                 
0 row(s) in 0.3180 seconds

 

过滤查询表内容

hbase(main):034:0> scan 'student'
ROW                          COLUMN+CELL                                            
 myrow-0000                  column=info:age,  timestamp=1501050432235, value=0
 myrow-0000                  column=info:name, timestamp=1501050432235, value=lily-0
 myrow-0000                  column=info:sex,  timestamp=1501050432235, value=male   
 myrow-0001                  column=info:age,  timestamp=1501050432246, value=1      
 myrow-0001                  column=info:name, timestamp=1501050432246, value=lily-1
 myrow-0001                  column=info:sex,  timestamp=1501050432246, value=female 
 myrow-0002                  column=info:age,  timestamp=1501050432250, value=2
 myrow-0002                  column=info:name, timestamp=1501050432250, value=lily-2
 myrow-0002                  column=info:sex,  timestamp=1501050432250, value=male   
 myrow-0003                  column=info:age,  timestamp=1501050432253, value=3      
 myrow-0003                  column=info:name, timestamp=1501050432253, value=lily-3
 myrow-0003                  column=info:sex,  timestamp=1501050432253, value=female 
 myrow-0004                  column=info:age,  timestamp=1501050432257, value=4      
 myrow-0004                  column=info:name, timestamp=1501050432257, value=lily-4
 myrow-0004                  column=info:sex,  timestamp=1501050432257, value=male   
 myrow-0005                  column=info:age,  timestamp=1501050432260, value=5      
 myrow-0005                  column=info:name, timestamp=1501050432260, value=lily-5
 myrow-0005                  column=info:sex,  timestamp=1501050432260, value=female 
 myrow-0006                  column=info:age,  timestamp=1501050432268, value=6      
 myrow-0006                  column=info:name, timestamp=1501050432268, value=lily-6
 myrow-0006                  column=info:sex,  timestamp=1501050432268, value=male   
 myrow-0007                  column=info:age,  timestamp=1501050432272, value=7      
 myrow-0007                  column=info:name, timestamp=1501050432272, value=lily-7
 myrow-0007                  column=info:sex,  timestamp=1501050432272, value=female 
 myrow-0008                  column=info:age,  timestamp=1501050432275, value=8      
 myrow-0008                  column=info:name, timestamp=1501050432275, value=lily-8
 myrow-0008                  column=info:sex,  timestamp=1501050432275, value=male   
 myrow-0009                  column=info:age,  timestamp=1501050432279, value=9      
 myrow-0009                  column=info:name, timestamp=1501050432279, value=lily-9
 myrow-0009                  column=info:sex,  timestamp=1501050432279, value=female 
10 row(s) in 0.0710 seconds

// 只查看info列簇 hbase(main):035:0> scan 'student', {COLUMN=>'info'} ROW COLUMN+CELL myrow-0000 column=info:age, timestamp=1501050432235, value=0 myrow-0000 column=info:name, timestamp=1501050432235, value=lily-0 myrow-0000 column=info:sex, timestamp=1501050432235, value=male myrow-0001 column=info:age, timestamp=1501050432246, value=1 myrow-0001 column=info:name, timestamp=1501050432246, value=lily-1 myrow-0001 column=info:sex, timestamp=1501050432246, value=female myrow-0002 column=info:age, timestamp=1501050432250, value=2 myrow-0002 column=info:name, timestamp=1501050432250, value=lily-2 myrow-0002 column=info:sex, timestamp=1501050432250, value=male myrow-0003 column=info:age, timestamp=1501050432253, value=3 myrow-0003 column=info:name, timestamp=1501050432253, value=lily-3 myrow-0003 column=info:sex, timestamp=1501050432253, value=female myrow-0004 column=info:age, timestamp=1501050432257, value=4 myrow-0004 column=info:name, timestamp=1501050432257, value=lily-4 myrow-0004 column=info:sex, timestamp=1501050432257, value=male myrow-0005 column=info:age, timestamp=1501050432260, value=5 myrow-0005 column=info:name, timestamp=1501050432260, value=lily-5 myrow-0005 column=info:sex, timestamp=1501050432260, value=female myrow-0006 column=info:age, timestamp=1501050432268, value=6 myrow-0006 column=info:name, timestamp=1501050432268, value=lily-6 myrow-0006 column=info:sex, timestamp=1501050432268, value=male myrow-0007 column=info:age, timestamp=1501050432272, value=7 myrow-0007 column=info:name, timestamp=1501050432272, value=lily-7 myrow-0007 column=info:sex, timestamp=1501050432272, value=female myrow-0008 column=info:age, timestamp=1501050432275, value=8 myrow-0008 column=info:name, timestamp=1501050432275, value=lily-8 myrow-0008 column=info:sex, timestamp=1501050432275, value=male myrow-0009 column=info:age, timestamp=1501050432279, value=9 myrow-0009 column=info:name, timestamp=1501050432279, value=lily-9 myrow-0009 column=info:sex, timestamp=1501050432279, value=female 10 row(s) in 0.0320 seconds

// 只查看info列簇的第一个列 hbase(main):036:0> scan 'student', {COLUMN=>'info', FILTER=>"(FirstKeyOnlyFilter())"} ROW COLUMN+CELL myrow-0000 column=info:age, timestamp=1501050432235, value=0 myrow-0001 column=info:age, timestamp=1501050432246, value=1 myrow-0002 column=info:age, timestamp=1501050432250, value=2 myrow-0003 column=info:age, timestamp=1501050432253, value=3 myrow-0004 column=info:age, timestamp=1501050432257, value=4 myrow-0005 column=info:age, timestamp=1501050432260, value=5 myrow-0006 column=info:age, timestamp=1501050432268, value=6 myrow-0007 column=info:age, timestamp=1501050432272, value=7 myrow-0008 column=info:age, timestamp=1501050432275, value=8 myrow-0009 column=info:age, timestamp=1501050432279, value=9 10 row(s) in 0.0170 seconds

 

指定显示行数,指定ROWKEY开始位置

hbase(main):011:0> scan 'student', {COLUMNS=>['info'], LIMIT=>1}
ROW                 COLUMN+CELL                                      
 myrow-0000         column=info:age, timestamp=1501050432235, value=0
 myrow-0000         column=info:name, timestamp=1501050432235, value=lily-0
 myrow-0000         column=info:sex, timestamp=1501050432235, value=male   
1 row(s) in 0.0370 seconds

hbase(main):001:0> scan 'student', {COLUMNS=>['info'], LIMIT=>2}
ROW                 COLUMN+CELL                                      
 myrow-0000         column=info:age, timestamp=1501050432235, value=0
 myrow-0000         column=info:name, timestamp=1501050432235, value=lily-0
 myrow-0000         column=info:sex, timestamp=1501050432235, value=male   
 myrow-0001         column=info:age, timestamp=1501050432246, value=1
 myrow-0001         column=info:name, timestamp=1501050432246, value=lily-1
 myrow-0001         column=info:sex, timestamp=1501050432246, value=female 
2 row(s) in 0.5840 seconds

// 指定ROWKEY从哪行开始查看
hbase(main):019:0> scan 'student', {COLUMNS=>['info'], STARTROW=>'myrow-0005'}
ROW                 COLUMN+CELL                                      
 myrow-0005         column=info:age, timestamp=1501050432260, value=5
 myrow-0005         column=info:name, timestamp=1501050432260, value=lily-5
 myrow-0005         column=info:sex, timestamp=1501050432260, value=female 
 myrow-0006         column=info:age, timestamp=1501050432268, value=6
 myrow-0006         column=info:name, timestamp=1501050432268, value=lily-6
 myrow-0006         column=info:sex, timestamp=1501050432268, value=male   
 myrow-0007         column=info:age, timestamp=1501050432272, value=7
 myrow-0007         column=info:name, timestamp=1501050432272, value=lily-7
 myrow-0007         column=info:sex, timestamp=1501050432272, value=female 
 myrow-0008         column=info:age, timestamp=1501050432275, value=8
 myrow-0008         column=info:name, timestamp=1501050432275, value=lily-8
 myrow-0008         column=info:sex, timestamp=1501050432275, value=male   
 myrow-0009         column=info:age, timestamp=1501050432279, value=9
 myrow-0009         column=info:name, timestamp=1501050432279, value=lily-9
 myrow-0009         column=info:sex, timestamp=1501050432279, value=female 
5 row(s) in 0.0390 seconds

  

posted @ 2017-08-01 13:59  Steven.Chow  阅读(482)  评论(0编辑  收藏  举报