表相关:
创建表
hbase(main):017:0* create 'ns_test:t1', {NAME=>'f1'}, {NAME=>'f2'}
0 row(s) in 2.3050 seconds
=> Hbase::Table - ns_test:t1
修改表
# 表t1增加列族f3
hbase(main):035:0> alter 'ns_test:t1' , 'f3'
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 3.0650 seconds
# 表t1删除列族f4
hbase(main):065:0> alter 'ns_test:t1', NAME => 'f4',METHOD => 'delete'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.2440 seconds
disable表
hbase(main):021:0* disable 'ns_test:t1'
0 row(s) in 2.3210 seconds
enable表
hbase(main):025:0> enable 'ns_test:t1'
0 row(s) in 1.3030 seconds
判断表是否存在
hbase(main):028:0> exists 'ns_test:t1'
Table ns_test:t1 does exist
0 row(s) in 0.0100 seconds
查看表相关信息
hbase(main):071:0> describe 'ns_test:t1'
Table ns_test:t1 is ENABLED
ns_test:t1
COLUMN FAMILIES DESCRIPTION
{NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'f2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'f3', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
3 row(s) in 0.0340 seconds
查看所有表
hbase(main):087:0* list
TABLE
ns2:t1
ns2:t2
ns_test:t1
3 row(s) in 0.0060 seconds
=> ["ns2:t1", "ns2:t2", "ns_test:t1"]
删除表(只有disable后的表才能被删除)
hbase(main):096:0> drop 'ns_test:t1'
0 row(s) in 1.2760 seconds
表数据操作:
添加数据
hbase(main):101:0> put 'ns_test:t1', '0001', 'f1:name', 'bob'
0 row(s) in 0.1650 seconds
全表扫描
hbase(main):105:0> scan 'ns_test:t1'
ROW COLUMN+CELL
0001 column=f1:age, timestamp=1532252491211, value=30
0001 column=f1:name, timestamp=1532252499881, value=bob
1 row(s) in 0.0460 seconds
获取某一行数据
# 获取一行的所有数据
hbase(main):001:0> get 'ns_test:t1', '0001'
COLUMN CELL
f1:age timestamp=1532252491211, value=30
f1:name timestamp=1532252499881, value=bob
2 row(s) in 0.3190 seconds
#获取一行某个列限定符的数据
hbase(main):014:0* get 'ns_test:t1', '0001', 'f1:age'
COLUMN CELL
f1:age timestamp=1532252491211, value=30
1 row(s) in 0.0140 seconds
删除一个cell的数据
hbase(main):002:0> delete 'ns_test:t1', '0001', 'f1:age'
0 row(s) in 0.2380 seconds
获取表的行数
hbase(main):006:0> count 'ns_test:t1'
1 row(s) in 0.0590 seconds
=> 1
清空表数据
hbase(main):013:0* truncate 'ns_test:t1'
Truncating 'ns_test:t1' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 3.8720 seconds
hbase(main):026:0> scan 'ns_test:t1'
ROW COLUMN+CELL
0 row(s) in 0.1380 seconds