1.
- hbase是bigtable的开源山寨版本。是建立的hdfs之上
- 它介于nosql和RDBMS之间
- 仅能通过主键(row key)和主键的range来检索数据
- 仅支持单行事务(可通过hive支持来实现多表join等复杂操作)
- 主要用来存储非结构化和半结构化的松散数据。
- 与hadoop一样,Hbase目标主要依靠横向扩展,通过不断增加廉价的商用服务器,来增加计算和存储能力。
2.表特点:
- 大:一个表可以有上亿行,上百万列
- 面向列:面向列(族)的存储和权限控制,列(族)独立检索。
- 稀疏:对于为空(null)的列,并不占用存储空间,因此,表可以设计的非常稀疏。
3.数据模型 为wide column模型
行键 | 时标 | 专栏家庭 contents | 专栏家庭 anchor | 专栏家庭 people |
---|---|---|---|---|
“ com.cnn.www” | 9天 | anchor:cnnsi.com =“ CNN” | ||
“ com.cnn.www” | 8天 | anchor:my.look.ca =“ CNN.com” | ||
“ com.cnn.www” | 6天 | contents:html =“ <html> ... | ||
“ com.cnn.www” | t5 | contents:html =“ <html> ... | ||
“ com.cnn.www” | 3天 | contents:html =“ <html> ... | ||
“ com.example.www” | 5天 | contents:html =“ <html> ... | people:author =“ John Doe” |
分为两行(“ com.cnn.www”,“ com.example.www”),三列族(contents,anchor,people),一个列族中有一列(contents:html/people:author)可以有多列,空列在实际表中不存在。时标为version
{
"com.cnn.www": {
contents: {
t6: contents:html: "<html>..."
t5: contents:html: "<html>..."
t3: contents:html: "<html>..."
}
anchor: {
t9: anchor:cnnsi.com = "CNN"
t8: anchor:my.look.ca = "CNN.com"
}
people: {}
}
"com.example.www": {
contents: {
t5: contents:html: "<html>..."
}
anchor: {}
people: {
t5: people:author: "John Doe"
}
}
}
ROW COLUMN+CELL
1001 column=contect:mail, timestamp=1522202414649, value=liupliup@cn.ibm.com
1001 column=contect:phone, timestamp=1522202430196, value=15962459503
1001 column=group:number, timestamp=1522202455929, value=1
1001 column=info:age, timestamp=1522202371257, value=34
1001 column=info:name, timestamp=1522202364156, value=liupeng
3.hbase shell命令
- 连接到hbase 安装目录中 ./bin/hbase shell
- version
- whoami
- status
- list :列出所有表
- describe 'table'
- {NAME => 'dynamic', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '
65536', REPLICATION_SCOPE => '0'} -
NAME => 'info', //列族 DATA_BLOCK_ENCODING => 'NONE', //数据块编码方式设置 BLOOMFILT => 'ROW' REPLICATION_SCOPE => '0', //配置HBase集群replication时需要将该参数设置为1. VERSIONS => '1', //设置保存的版本数 COMPRESSION => 'NONE', //设置压缩算法 MIN_VERSIONS => '0', //最小存储版本数 KEEP_DELETED_CELLS => 'false', //参见:http://hbase.apache.org/book.html#cf.keep.deleted BLOCKSIZE => '65536', //设置HFile数据块大小(默认64kb) IN_MEMORY => 'false',//设置激进缓存,优先考虑将该列族放入块缓存中, //针对随机读操作相对较多的列族可以设置该属性为true BLOCKCACHE => 'true' //数据块缓存属性
- {NAME => 'dynamic', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '
- is_enabled 'tablename' 检查表是否启用
- count 'user_dynamic' 计算数量
- scan 'Test',{LIMIT=>10}