hadoop學習筆記(11)——hbase shell簡單操作示例

thinkpadshi發表於2016-01-25

1) 表設計

這裡寫圖片描述

2) 建表scores,具有兩個列族:grad和course

[root@master bin]# hbase shell
hbase(main):002:0> create 'scores','grade','course'
0 row(s) in 7.6340 seconds
=> Hbase::Table - scores

3) 檢視Hasee中有哪些表

hbase(main):003:0> list
TABLE                                                                                                                                 
scores                                                                                                                                
1 row(s) in 0.2190 seconds
=> ["scores"]

4) 檢視錶結構

hbase(main):004:0> describe 'scores'
Table scores is ENABLED                                                                                                               
scores                                                                                                                                
COLUMN FAMILIES DESCRIPTION                                                                                                           
{NAME => 'course', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NON
E', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 't
rue'}                                                                                                                                 
{NAME => 'grade', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE
', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'tr
ue'}                                                                                                                                  
2 row(s) in 0.5300 seconds

5) 新增資料

a) 行名稱為 Tom 列名為grad, 值為1

hbase(main):005:0> put 'scores','Tom','grade:','1'

b) 給Tom這一行的資料的列族新增一列

hbase(main):005:0> put 'scores','Tom','course:math','93'

c) 給Tom這一行的資料的列族新增一列

hbase(main):005:0> put 'scores','Tom','course:art','82'

d) 行名稱為 Sam 列名為grad, 值為2

hbase(main):005:0> put 'scores','Sam','grade:','2'

e) 給Sam這一行的資料的列族新增一列

hbase(main):005:0> put 'scores','Sam','course:math','97'

f) 給Sam這一行的資料的列族新增一列

hbase(main):005:0> put 'scores','Sam','course:art','76'

6) 檢視scores表中Tom的相關資料

hbase(main):014:0> get 'scores','Tom'
COLUMN                             CELL                                                                                               
 course:art                        timestamp=1453694601377, value=76                                                                  
 course:math                       timestamp=1453694113182, value=93                                                                  
 grade:                            timestamp=1453694015658, value=1                                                                   
3 row(s) in 0.0190 seconds

7) 檢視scores表中所有資料

hbase(main):015:0> scan 'scores'
ROW                   COLUMN+CELL                                                                                        
 Sam        column=course:art, timestamp=1453694637826, value=82                                               
 Sam        column=course:math, timestamp=1453694531258, value=97                                              
 Sam        column=grade:, timestamp=1453694479156, value=2                                                    
 Tom        column=course:art, timestamp=1453694601377, value=76                                               
 Tom        column=course:math, timestamp=1453694113182, value=93                                              
 Tom        column=grade:, timestamp=1453694015658, value=1                                                    
2 row(s) in 0.1770 seconds

8) 檢視scores表中所有資料courses列族的所有資料

hbase(main):015:0> scan "scores",{COLUMNS => ['course:math']}
hbase(main):015:0> scan "scores",{COLUMNS => ['course']}
ROW       COLUMN+CELL                                                                                        
 Sam      column=course:art, timestamp=1453694637826, value=82                                               
 Sam      column=course:math, timestamp=1453694531258, value=97                                              
 Tom      column=course:art, timestamp=1453694601377, value=76                                               
 Tom      column=course:math, timestamp=1453694113182, value=93                                              
2 row(s) in 0.0250 seconds

9) delete表記錄

hbase(main):015:0> delete 'scores','Tom','course:ctrl'

10) count表記錄

hbase(main):025:0> count 'scores'
2 row(s) in 0.1310 seconds
=> 2

11) exists表

hbase(main):027:0> exists 'scores'
Table scores does exist                                                                                                               
0 row(s) in 0.0120 seconds

相關文章