HQL常用记录小结

1)查看帮助信息
hbase(main):027:0> help
HBase Shell, version 0.96.0-hadoop1, r1531434, Fri Oct 11 15:11:29 PDT 2013
Type ‘help “COMMAND”‘, (e.g. ‘help “get”‘ — the quotes are necessary) for help on a specific command.
Commands are grouped. Type ‘help “COMMAND_GROUP”‘, (e.g. ‘help “general”‘) for help on a command group.

COMMAND GROUPS:
Group name: general
Commands: status, table_help, version, whoami

Group name: ddl
Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, show_filters

Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
…….

2)查看数据库版本和状态
hbase(main):004:0> version
0.96.0-hadoop1, r1531434, Fri Oct 11 15:11:29 PDT 2013

hbase(main):005:0> status
2 servers, 0 dead, 1.5000 average load

3)创建表
hbase(main):004:0> create ‘member’,’member_id’,’address’,’info’
0 row(s) in 0.4930 seconds

=> Hbase::Table – member
hbase(main):005:0> list
TABLE
member
1 row(s) in 0.0250 seconds

=> [“member”]

4)查看表的信息
hbase(main):012:0>list TABLE member 1 row(s) in 0.0160seconds hbase(main):006:0>describe ‘member’ DESCRIPTION
ENABLED
{NAME => ‘member’, FAMILIES => [{NAME=> ‘address’, BLOOMFILTER => ‘NONE’, REPLICATION_SCOPE => ‘0’, true
VERSIONS => ‘3’, COMPRESSION => ‘NONE’,TTL => ‘2147483647’, BLOCKSIZE => ‘65536’, IN_MEMORY => ‘false’, BLOCKCACHE => ‘true’}, {NAME =>’info’, BLOOMFILTER => ‘NONE’, REPLICATION_SCOPE => ‘0’, VERSI
ONS => ‘3’, COMPRESSION => ‘NONE’, TTL=> ‘2147483647’, BLOCKSIZE => ‘65536’, IN_MEMORY => ‘false’,
BLOCKCACHE => ‘true’}]} 1 row(s) in 0.0230seconds

5)删除表

hbase(main):029:0>disable ‘temp_table’
0 row(s) in 2.0590seconds

hbase(main):030:0>drop ‘temp_table’
0 row(s) in 1.1070seconds

6)插入记录

put’member’,’scutshuxue’,’info:age’,’24’
put’member’,’scutshuxue’,’info:birthday’,’1987-06-17′
put’member’,’scutshuxue’,’info:company’,’alibaba’
put’member’,’scutshuxue’,’address:contry’,’china’
put’member’,’scutshuxue’,’address:province’,’zhejiang’
put’member’,’scutshuxue’,’address:city’,’hangzhou’
put’member’,’xiaofeng’,’info:birthday’,’1987-4-17′
put’member’,’xiaofeng’,’info:favorite’,’movie’
put’member’,’xiaofeng’,’info:company’,’alibaba’
put’member’,’xiaofeng’,’address:contry’,’china’
put’member’,’xiaofeng’,’address:province’,’guangdong’
put’member’,’xiaofeng’,’address:city’,’jieyang’
put’member’,’xiaofeng’,’address:town’,’xianqiao’

7)获取一个行健所有数据

hbase(main):028:0> get ‘member’,’scutshuxue’
COLUMN                           CELL
address:contry                  timestamp=1384788878632, value=china
address:province                timestamp=1384789314697, value=zhejiang
info:age                        timestamp=1384789011274, value=99
info:birthday                   timestamp=1384788854277, value=1987-06-17
info:company                    timestamp=1384788869183, value=alibaba
5 row(s) in 0.0200 seconds

8)获取一个行健一个列族所有数据
hbase(main):029:0> get ‘member’,’scutshuxue’,’info’
COLUMN                           CELL
info:age                        timestamp=1384789011274, value=99
info:birthday                   timestamp=1384788854277, value=1987-06-17
info:company                    timestamp=1384788869183, value=alibaba
3 row(s) in 0.0140 seconds

9)获取一个行健一个列族中一个列的所有数据
hbase(main):030:0> get ‘member’,’scutshuxue’,’info:age’
COLUMN                           CELL
info:age                        timestamp=1384789011274, value=99
1 row(s) in 0.0110 seconds

10)更新一条记录

hbase(main):004:0>put ‘member’,’scutshuxue’,’info:age’ ,’99’
0 row(s) in 0.0210seconds

hbase(main):005:0>get ‘member’,’scutshuxue’,’info:age’
COLUMN  CELL

info:age       timestamp=1321586571843,value=99

1 row(s) in 0.0180seconds

11)通过timestamp来获取数据

hbase(main):010:0>get ‘member’,’scutshuxue’,{COLUMN=>’info:age’,TIMESTAMP=>1321586238965}
COLUMN                CELL
info:age            timestamp=1321586238965,value=24

1 row(s) in 0.0140seconds

hbase(main):011:0>get ‘member’,’scutshuxue’,{COLUMN=>’info:age’,TIMESTAMP=>1321586571843}
COLUMN                     CELL info:age                        timestamp=1321586571843,value=99

1 row(s) in 0.0180seconds

12)全表扫描
hbase(main):031:0> scan ‘member’
ROW                              COLUMN+CELL
scutshuxue                      column=address:contry, timestamp=1384788878632, value=china
scutshuxue                      column=address:province, timestamp=1384789314697, value=zhejiang
scutshuxue                      column=info:age, timestamp=1384789011274, value=99
scutshuxue                      column=info:birthday, timestamp=1384788854277, value=1987-06-17
scutshuxue                      column=info:company, timestamp=1384788869183, value=alibaba
xiaofeng                        column=info:favorite, timestamp=1384789354881, value=movie
2 row(s) in 0.0460 seconds

13)查询表中有多少行
hbase(main):032:0> count ‘member’
2 row(s) in 0.0110 seconds

=> 2

14)删除指定行健的字段

hbase(main):016:0>delete ‘member’,’temp’,’info:age’
0 row(s) in 0.0150seconds hbase(main):018:0>get ‘member’,’temp’ COLUMN CELL

0 row(s) in 0.0150seconds

15)删除整行
hbase(main):033:0> deleteall ‘member’,’xiaofeng’
0 row(s) in 0.0640 seconds

16)清空表
hbase(main):034:0> truncate ‘member’
Truncating ‘member’ table (it may take a while):
– Disabling table…
– Dropping table…
– Creating table…
0 row(s) in 2.0570 seconds

标签