- quick start from official Hbase
hbase(main):003:0> create 'test', 'cf'
0 row(s) in 1.2200 seconds
hbase(main):003:0> list 'test'
..
1 row(s) in 0.0550 seconds
hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.0560 seconds
hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0370 seconds
hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0450 seconds 另外常见的命令还有,
hbase(main):006:0> truncate 'test'
(注:'truncate'功能类似mysql,将表的数据清空。慎用!)
hbase(main):006:0> describe 'test'
(注:查询test表的列族)
hbase(main):006:0> count 'test'
(注:统计‘test’表中的记录数)
hbase(main):006:0> get 'test','row1'
(注:获取一条记录)
hbase(main):006:0> scan 'test'
(注:查询全表)
hbase(main):006:0> delete 'test','cf:a'
(注:删除test表所以记录的一列,需慎重!)
hbase(main):006:0> deleteall 'test','row1'
(注:删除test表的整条记录,包含row1单条记录的任意column)
- Demos
将关系型的people表转换为hbase列式存储的方式如下
people表 | sex | age | summary | story |
ZhangSan | M | 19 | Summary for ZhangSan | 张三的故事 |
WangMing | F | 20 | Summary for WangMing | 王明,明之歌 |
id | column | value | timestamp |
p|ZhangSan | property:sex | M | xx(系统时间) |
p|ZhangSan | property:age | 19 | xx |
p|ZhangSan | detail:summary | Summary for ZhangSan | xx |
p|ZhangSan | detail:story | 张三的故事 | xx |
p|WangMing | property:sex | F | xx |
p|WangMing | property:age | 20 | xx |
p|WangMing | detail:summary | Summary for WangMing | xx |
p|WangMing | detail:story | 王明,明之歌 | xx |
具体转换如下图: