使用HBase Shell接口的注意事項
HBase Shell 接口本身沒有什么可談的,網(wǎng)上許多內(nèi)容都有介紹, 半個小時就可以入門。同事們要我推薦一下,那就推薦三個如下:
(1) http://wiki.apache.org/hadoop/Hbase/Shell
(2) ./hbase shell 打開shell, run 'help' to get help information
(3)http://qibaopeng2000.blog.163.com/blog/static/691776952010112444553279/ (這個網(wǎng)上很多相同或者類似的內(nèi)容)
總結培訓當天反饋的問題,新手們需要注意幾點:
問題1, HBase(可以理解為不需要建'name'列,hbase自動建立一個用于存儲“行標識”的“列”),舉例如下:
例一:
- reate 'employees', 'SN', 'department', 'address' 這個employees表的結構將為:
- row_id SN department address
- --------------------------------------------------
共有四列,***列用于標識行, 這里你可以當做‘name’來用
插入數(shù)據(jù): put 'employees', 'HongKong', 'SN:', '20080501'
注意是put,不是Ruby的puts
對比的情況:
創(chuàng)建表: create 'employees', 'name', 'SN', 'department', 'address'
此時數(shù)據(jù)為: 除了標識本身外,還有一個name列,下面簡單設置為一樣的值。
put 'employees', 'HongKong', 'name:', 'HongKong'
例二:
網(wǎng)上流行資料的例子:
一個存儲學生成績的表:
- name grad course:math course:art
- Tom 1 87 97
- Jerry 2 100 80
這里grad對于表來說是一個列,course對于表來說是一個列族,這個列族由兩個列組成:math和art,當然我們可以根據(jù)我們的需要在 course中建立更多的列族,如computer,physics等相應的列添加入course列族. 建立一個表格 scores 具有兩個列族grad 和courese
- hbase(main):002:0> create 'scores', 'grade', 'course'
- 0 row(s) in 4.1610 seconds
分析,請注意,為什么創(chuàng)建的表是沒有“name”這一列呢? 其實這里的name列就對應例一的row_id,不用顯式創(chuàng)建的。
導入數(shù)據(jù)為: put 'scores', 'Tom', 'grade:', '1' , Tom對應name
問題2. 參數(shù)的警告說明
很多人開始都碰到類似
- hbase(main):034:0> put 'employees', 'HongKong', 'name:', 'Hongkong', 'SN:', '20080501'
- ArgumentError: wrong number of arguments (6 for 5)
- hbase(main):033:0> put 'employees', 'Kong', 'name:' 'Kong'
- ArgumentError: wrong number of arguments (3 for 4)
這是參數(shù)數(shù)量不對的說明, 請尤其注意逗號, 空格不能用來分隔參數(shù)的。
以put為例,參數(shù)一般為5個, 6個 10個都報錯。但為什么又有(3 for 4)呢? 5和4個的時候可以工作呢? timestamp 是optional的。所以參數(shù)多的時候, 按照上限5報警,少的時候按照下限4報警。
- put Put a cell 'value' at specified table/row/column and optionally
- timestamp coordinates. To put a cell value into table 't1' at
- row 'r1' under column 'c1' marked with the time 'ts1', do:
- hbase> put 't1', 'r1', 'c1', 'value', ts1
問題3. 插入數(shù)據(jù)
- hbase(main):030:0> put 'employees', 'Tom', 'name:' 'Tom', 'SN:', '20091101', 'department:', 'D&R', 'address:country', 'China', 'address:city', 'Beijing'
- ArgumentError: wrong number of arguments (11 for 5)
怎么回事呢? 不要老想著SQL, put插入的Cell數(shù)據(jù), 這么多一起來,當然報錯咯
問題4. 刪除表必須先停,然后再刪: To remove the table, you must first disable it before dropping it
- hbase(main):025:0> disable 'test'
- 09/04/19 06:40:13 INFO client.HBaseAdmin: Disabled test
- 0 row(s) in 6.0426 seconds
- hbase(main):026:0> drop 'test'
- 09/04/19 06:40:17 INFO client.HBaseAdmin: Deleted test
問題5. 如何運行腳本文件
- ${HBASE_HOME}/bin/hbase shell PATH_TO_SCRIPT
- 示例:
- ./hbase shell /data/automation/create_import.hbase
- --------------------------------------------------------------------------------------------
- disable 'employees'
- drop 'employees'
- create 'employees', 'SN', 'department', 'address'
- put 'employees', 'HongKong', 'SN:', '20080501189'
- put 'employees', 'HongKong', 'department:', 'R&D'
- put 'employees', 'HongKong', 'address:country', 'China'
- put 'employees', 'HongKong', 'address:city', 'Beijing'
- put 'employees', 'Cudynia', 'SN:', '20010807368'
- put 'employees', 'Cudynia', 'department:', 'HR'
- put 'employees', 'Cudynia', 'address:country', 'US'
- put 'employees', 'Cudynia', 'address:city', 'San Francisco'
- exit
原文鏈接:http://blog.csdn.net/linhx/article/details/6634812
【編輯推薦】
- 主流NoSQL數(shù)據(jù)庫評測之HBase
- HBase數(shù)據(jù)庫性能調(diào)優(yōu)
- Facebook實時信息系統(tǒng):HBase每月存儲1350億條信息
- HBase性能深度分析