首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

HBASE的shell应用

2012-12-22 
HBASE的shell使用也来hbase的shell吧首先是登录hbase 了:hbase(main):001:0 create tbname,row,colu

HBASE的shell使用

也来hbase的shell吧

首先是登录hbase 了:

hbase(main):001:0> create 'tbname','row','column1','column2'
0 row(s) in 1.0730 seconds


hbase(main):004:0> list 'tbname'
TABLE                                                                           
tbname                                                                          
1 row(s) in 0.0290 seconds

Put操作:

hbase(main):005:0> put 'tbname','row','column1:a','a:value'
0 row(s) in 0.2400 seconds

hbase(main):006:0> put 'tbname','row','column2:ff','ff:value'
0 row(s) in 0.0080 seconds

hbase(main):007:0> put 'tbname','row','column1:b','b:value'  
0 row(s) in 0.0310 seconds

hbase(main):008:0> put 'tbname','row','column1:c','c:value'
0 row(s) in 0.0080 seconds

hbase(main):009:0> put 'tbname','row','column2:gg','gg:value'

0 row(s) in 0.0080 seconds

SCAN操作

hbase(main):011:0> scan 'tbname'
ROW                   COLUMN+CELL                                               
 row                  column=column1:a, timestamp=1354556840011, value=a:value  
 row                  column=column1:b, timestamp=1354556861963, value=b:value  
 row                  column=column1:c, timestamp=1354556868862, value=c:value  
 row                  column=column2:ff, timestamp=1354556852040, value=ff:value
 row                  column=column2:gg, timestamp=1354556885196, value=gg:value
1 row(s) in 0.1500 seconds

GET操作获取表中的指定行

hbase(main):012:0> get 'tbname','row'

COLUMN                CELL                                                      
 column1:a            timestamp=1354556840011, value=a:value                    
 column1:b            timestamp=1354556861963, value=b:value                    
 column1:c            timestamp=1354556868862, value=c:value                    
 column2:ff           timestamp=1354556852040, value=ff:value                   
 column2:gg           timestamp=1354556885196, value=gg:value                   
5 row(s) in 0.0230 seconds

GET操作,获取指定行列

hbase(main):014:0> get 'tbname','row','column1:a'

COLUMN                CELL                                                      
 column1:a            timestamp=1354556840011, value=a:value                    
1 row(s) in 0.0150 seconds

参考:http://www.yankay.com/wp-content/hbase/book.html#shell_exercises

创建一个名为 test 的表,这个表只有一个 column family 为cf。可以列出所有的表来检查创建情况,然后插入些值。

hbase(main):003:0> create 'test', 'cf'0 row(s) in 1.2200 secondshbase(main):003:0> list 'table'test1 row(s) in 0.0550 secondshbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1'0 row(s) in 0.0560 secondshbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2'0 row(s) in 0.0370 secondshbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3'0 row(s) in 0.0450 seconds

以上我们分别插入了3行。第一个行key为row1, 列为 cf:a, 值是 value1。Hbase中的列是由 column family前缀和列的名字组成的,以冒号间隔。例如这一行的列名就是a.

检查插入情况.

Scan这个表,操作如下

hbase(main):007:0> scan 'test'ROW        COLUMN+CELLrow1       column=cf:a, timestamp=1288380727188, value=value1row2       column=cf:b, timestamp=1288380738440, value=value2row3       column=cf:c, timestamp=1288380747365, value=value33 row(s) in 0.0590 seconds

Get一行,操作如下

hbase(main):008:0> get 'test', 'row1'COLUMN      CELLcf:a        timestamp=1288380727188, value=value11 row(s) in 0.0400 seconds



热点排行