使用HBase Shell接口的幾點(diǎn)注意事項(xiàng)
本文主要介紹了使用HBase Shell接口的幾點(diǎn)注意事項(xiàng),問題如下:
問題1, HBase(可以理解為不需要建'name'列,hbase自動建立一個用于存儲“行標(biāo)識”的“列”),舉例如下:
例一:
- create 'employees', 'SN', 'department', 'address' 這個employees表的結(jié)構(gòu)將為:
- row_id SN department address
- --------------------------------------------------
共有四列,***列用于標(biāo)識行, 這里你可以當(dāng)做‘name’來用
插入數(shù)據(jù): put 'employees', 'HongKong', 'SN:', '20080501'
注意是put,不是Ruby的puts
對比的情況:
創(chuàng)建表:
- create 'employees', 'name', 'SN', 'department', 'address'
此時數(shù)據(jù)為: 除了標(biāo)識本身外,還有一個name列,下面簡單設(shè)置為一樣的值。
- put 'employees', 'HongKong', 'name:', 'HongKong'
例二:
網(wǎng)上流行資料的例子:
一個存儲學(xué)生成績的表:
- name grad course:math course:art
- Tom 1 87
- 97
- Tom 1 87
- 97
- Jerry 2 100 80
這里grad對于表來說是一個列,course對于表來說是一個列族,這個列族由兩個列組成:math和art,當(dāng)然我們可以根據(jù)我們的需要在course中建立更多的列族,如computer,physics等相應(yīng)的列添加入course列族. 建立一個表格 scores 具有兩個列族grad 和courese
- hbase(main):002:0> create 'scores', 'grade', 'course'
- 0 row(s) in 4.1610 seconds
分析,請注意,為什么創(chuàng)建的表是沒有“name”這一列呢? 其實(shí)這里的name列就對應(yīng)例一的row_id,不用顯式創(chuàng)建的。
導(dǎo)入數(shù)據(jù)為: put 'scores', 'Tom', 'grade:', '1' , Tom對應(yīng)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 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ù), 這么多一起來,當(dāng)然報錯咯
問題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. 如何運(yùn)行腳本文件
${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
關(guān)于使用HBase Shell 接口的注意事項(xiàng)就介紹到這里了,希望能夠帶給您收獲!
【編輯推薦】


2010-11-26 16:27:01
2011-02-16 08:56:19
2011-04-14 11:28:07




