HBase基礎之Hbase shell常用操作

來源:互聯網
上載者:User

標籤:des   style   blog   color   io   strong   資料   div   log   

一般操作

查看伺服器狀態

status

查看hbase版本

version

 

DDL操作

建立表

create ‘member‘,‘member_id‘,‘address‘,‘info‘

建立了3個列族,分別是member_id, address, info

知識點回顧:cf是schema的一部分,而column不是

查看錶資訊

describe ‘member‘

DESCRIPTION ENABLED ‘member‘, {NAME => ‘address‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTE true R => ‘ROW‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘ NONE‘, MIN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, BLOCKCACHE => ‘tru e‘}, {NAME => ‘info‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘RO W‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, M IN_VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘}, {NA ME => ‘member_id‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘ROW‘, REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, MIN_ VERSIONS => ‘0‘, TTL => ‘2147483647‘, KEEP_DELETED_CELLS => ‘false‘, BL OCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘} 1 row(s) in 0.1800 seconds

查詢所有的表

list

刪除一個列族

member表建了3個列族,但是發現member_id這個列族是多餘的,因為他就是主鍵,所以我們要將其刪除。

alter ‘member‘,‘delete‘=>‘member_id‘ 

drop表

為了測試drop,先建立一個表

create ‘tmp_table‘,‘info‘

刪除表之前需要先將表disable再drop

disable ‘tmp_table‘drop ‘tmp_table‘

判斷表是否enable

is_enabled ‘member‘

判斷表是否disabled

is_disabled ‘member‘

 

DML操作

插入記錄

格式:put 表名 row_key cf:column value

put ‘member‘,‘luogankun‘,‘info:age‘,‘27‘put ‘member‘,‘luogankun‘,‘info:birthday‘,‘1986-09-05‘put ‘member‘,‘luogankun‘,‘info:company‘,‘asinainfo-linkage‘put ‘member‘,‘luogankun‘,‘address:country‘,‘china‘put ‘member‘,‘luogankun‘,‘address:province‘,‘beijing‘put ‘member‘,‘luogankun‘,‘address:city‘,‘beijing‘put ‘member‘,‘spring‘,‘info:age‘,‘27‘put ‘member‘,‘spring‘,‘info:birthday‘,‘1986-05-14‘put ‘member‘,‘spring‘,‘info:company‘,‘asinainfo-linkage‘put ‘member‘,‘spring‘,‘address:country‘,‘china‘put ‘member‘,‘spring‘,‘address:province‘,‘hubei‘put ‘member‘,‘spring‘,‘address:city‘,‘wuhan‘put ‘member‘,‘spring‘,‘info:favorite‘,‘shopping‘

知識點回顧: column完全動態擴充,每行可以有不同的columns。

擷取一個rowkey的所有資料

格式:get 表名 row_key

get ‘member‘,‘luogankun‘COLUMN                       CELL                                                                               address:city                timestamp=1409122962541, value=beijing                                             address:country             timestamp=1409122962468, value=china                                               address:province            timestamp=1409122962510, value=beijing                                             info:age                    timestamp=1409122962328, value=27                                                  info:birthday               timestamp=1409122962399, value=1986-09-05                                          info:company                timestamp=1409122962434, value=asinainfo-linkage 

知識點回顧:htable按rowkey字典序(1,10,100,2)自動排序,每行包含任意數量的columns,columns按照columnkey(address:city,address:country,address:province,info:age,info:birthday,info:company)自動排序

擷取一個id,一個列族的所有資料
格式: get 表名 row_key column

get ‘member‘,‘luogankun‘,‘info‘COLUMN                       CELL                                                                               info:age                    timestamp=1409122962328, value=27                                                  info:birthday               timestamp=1409122962399, value=1986-09-05                                          info:company                timestamp=1409122962434, value=asinainfo-linkage 

擷取一個id,一個列族中一個列的所有資料
格式:get 表名 row_key cf:column

get ‘member‘,‘luogankun‘,‘info:age‘COLUMN                       CELL                                                                               info:age                    timestamp=1409122962328, value=27

更新一條記錄
格式: put 表名 row_key cf:column value
將luogankun的年齡改成18

put ‘member‘,‘luogankun‘,‘info:age‘,‘18‘get ‘member‘,‘luogankun‘,‘info:age‘COLUMN                       CELL                                                                               info:age                    timestamp=1409123175384, value=18 

知識點回顧:查詢預設返回最新的值

通過timestamp來擷取指定版本的資料
格式: get 表名 row_key {COLUMN=>‘cf:column‘,TIMESTAMP=>xxxxxx}

get ‘member‘,‘luogankun‘,{COLUMN=>‘info:age‘,TIMESTAMP=>1409122962328}COLUMN                       CELL                                                                               info:age                    timestamp=1409122962328, value=27                                                 get ‘member‘,‘luogankun‘,{COLUMN=>‘info:age‘,TIMESTAMP=>1409123175384}
COLUMN CELL info:age timestamp=1409123175384, value=18

知識點回顧:每個column可以有任意數量的values,按timestamp倒序自動排序;tableName+rowkey+column+timestamp==>value

全表掃描
格式:scan 表名

scan ‘member‘ROW                          COLUMN+CELL                                                                        luogankun                   column=address:city, timestamp=1409122962541, value=beijing                        luogankun                   column=address:country, timestamp=1409122962468, value=china                       luogankun                   column=address:province, timestamp=1409122962510, value=beijing                    luogankun                   column=info:age, timestamp=1409123175384, value=18                                 luogankun                   column=info:birthday, timestamp=1409122962399, value=1986-09-05                    luogankun                   column=info:company, timestamp=1409122962434, value=asinainfo-linkage              spring                      column=address:city, timestamp=1409122962828, value=wuhan                          spring                      column=address:country, timestamp=1409122962754, value=china                       spring                      column=address:province, timestamp=1409122962787, value=hubei                      spring                      column=info:age, timestamp=1409122962592, value=27                                 spring                      column=info:birthday, timestamp=1409122962623, value=1986-05-14                    spring                      column=info:company, timestamp=1409122962670, value=asinainfo-linkage              spring                      column=info:favorite, timestamp=1409122963494, value=shopping      

刪除id為spring的值的‘info:age‘欄位
格式:delete 表名 row_key cf:column
先查看

get ‘member‘,‘spring‘,‘info:age‘COLUMN                       CELL                                                                               info:age                    timestamp=1409122962592, value=27

再刪除

delete ‘member‘,‘spring‘,‘info:age‘
再查看對比是否已經刪除
get ‘member‘,‘spring‘,‘info:age‘COLUMN                       CELL                                                                              0 row(s) 

查詢表中有多少行
格式:count 表名

count ‘member‘

刪除整行
格式: deleteall 表名 row_key

deleteall ‘member‘,‘spring‘

將整張表清空
格式: truncate 表名

truncate ‘member‘Truncating ‘member‘ table (it may take a while): - Disabling table... - Dropping table... - Creating table...

可以看出,hbase是先將掉disable掉,然後drop掉後重建表來實現truncate的功能的。

 

HBase基礎之Hbase shell常用操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.