{{{ #!html
Hbase 使用方法
HBase 0.20 + Hadoop 0.20
}}} [wiki:NCHCCloudCourse110721#第二天 回課程大綱] [[PageOutline]] = 列出所有 table = {{{ hbase(main):> list }}} = 新增 table = A . 直接增加一個表 t2 {{{ hbase(main):> create 't2' }}} B . 增加一個擁有 'f1','f2','fn' 為 column family 的表: t1 {{{ hbase(main):> create 't1','f1','f2','fn' }}} = 查詢 Table 欄位 = {{{ hbase(main):> describe 't1' }}} 執行結果參考 {{{ #!text hbase(main):> describe 't1' DESCRIPTION ENABLED {NAME => 't1', FAMILIES => [{NAME => 'f1', COMPRESSION => 'NONE', VERS true IONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => ' false', BLOCKCACHE => 'true'}, {NAME => 'f2', COMPRESSION => 'NONE', V ERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY = > 'false', BLOCKCACHE => 'true'}, {NAME => 'fn', COMPRESSION => 'NONE' , VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMOR Y => 'false', BLOCKCACHE => 'true'}]} }}} = 加入cell-value = 需先擁有表 t1 與column-family : f1 並且加入一個 column-quantifier c1 {{{ hbase(main):> put 't1', 'r1', 'f1', 'v1' hbase(main):> put 't1', 'r1', 'f1:c1', 'v2' hbase(main):> put 't1', 'r2', 'f2', 'v3' hbase(main):> put 't1', 'r2', 'f2:c2', 'v4' }}} {{{ #!html
Table: 't1'
row-key'f1''f2''fn'column-family
*'c1'*'c2'*column-quantifier
r1v1
v2
r2v3
v4
}}} = 列出cell-value = A . 列出一列(row) {{{ hbase(main):> get 't1', 'r1' }}} 執行結果參考 {{{ #!text COLUMN CELL f1: timestamp=1285737082689, value=v1 f1:c1 timestamp=1285737085874, value=v2 }}} {{{ #!html
Table: 't1'
row-key'f1''f2''fn'column-family
*'c1'*'c2'*column-quantifier
r1v1
v2
r2v3
v4
}}} B . 列出一個 cell 的值 {{{ hbase(main):> get 't1', 'r1', {COLUMN => 'f1:c1'} }}}     執行結果參考 {{{ #!text COLUMN CELL f1:c1 timestamp=1285737085874, value=v2 }}} {{{ #!html
Table: 't1'
row-key'f1''f2''fn'column-family
*'c1'*'c2'*column-quantifier
r1v1
v2
r2v3
v4
}}} = 刪除 cell-value = {{{ hbase(main):> deleteall 't1','r1' }}} 執行結果:會把 row-key 是 '!r1' 的所有紀錄。此時資料表 't1' 會變成如下表所示。 {{{ hbase(main):> scan 't1' ROW COLUMN+CELL r2 column=f2:, timestamp=1285737091644, value=v3 r2 column=f2:c2, timestamp=1285737094157, value=v4 }}} {{{ #!html
Table: 't1'
row-key'f1''f2''fn'column-family
*'c1'*'c2'*column-quantifier
 
r2v3
v4
}}} = 加入column family = {{{ hbase(main):> disable 't1' hbase(main):> alter 't1', {NAME => 'f3'} hbase(main):> enable 't1' }}}     執行結果:多了一個 column-family 'f3' 可以用 describe 指令查詢,結果示意如下表: {{{ hbase(main):021:0> describe 't1' DESCRIPTION ENABLED {NAME => 't1', FAMILIES => [{NAME => 'f1', COMPRESSION => 'NONE', VERS true IONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => ' false', BLOCKCACHE => 'true'}, {NAME => 'f2', COMPRESSION => 'NONE', V ERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY = > 'false', BLOCKCACHE => 'true'}, {NAME => 'f3', VERSIONS => '3', COMP RESSION => 'NONE', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMOR Y => 'false', BLOCKCACHE => 'true'}, {NAME => 'fn', COMPRESSION => 'NO NE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_ME MORY => 'false', BLOCKCACHE => 'true'}]} }}} {{{ #!html
Table: 't1'
row-key'f1''f2''f3''fn'column-family
*'c1'*'c2'**column-quantifier
r2v3
v4
}}} = 刪除column family = {{{ hbase(main):> disable 't1' hbase(main):> alter 't1', {NAME => 'f1', METHOD => 'delete'} hbase(main):> enable 't1' }}}     執行結果:會移除 column family 為 'f1' 的所有欄位,可用 describe 指令確認,結果如下表所示。 {{{ hbase(main):053:0> describe 't1' DESCRIPTION ENABLED {NAME => 't1', FAMILIES => [{NAME => 'f2', COMPRESSION => 'NONE', VERS true IONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => ' false', BLOCKCACHE => 'true'}, {NAME => 'f3', COMPRESSION => 'NONE', V ERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY = > 'false', BLOCKCACHE => 'true'}, {NAME => 'fn', COMPRESSION => 'NONE' , VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMOR Y => 'false', BLOCKCACHE => 'true'}]} 1 row(s) in 0.0200 seconds }}} {{{ #!html
Table: 't1'
row-key 'f2''f3''fn'column-family
*'c2'**column-quantifier
r2v3
v4
}}} = 節點狀態 = {{{ hbase(main):> status }}}     = 刪除整張table = {{{ hbase(main):> truncate 't1' }}} * 執行完 truncate 後,所有 't1' 的內容都會被移除。但此時,下 list 還會有 't1' 這個表格存在。 {{{ hbase(main):> disable 't1' hbase(main):> drop 't1' }}}     * 要完整移除 't1' 資料表,必須使用 disable 先將 't1' 停用,再用 drop 指令把 't1' 完全刪除。