@awsekfozc
2016-01-22T22:55:57.000000Z
字数 1386
阅读 2482
Hbase
##创建表,单个列簇hbase> create 't1', 'f1'##创建表,多列簇hbase> create 't1', 'f1', 'f2'##创建表,给列簇指定属性# NAME:列簇名hbase> create 't1', {NAME => 'f1'}# VERSIONS:版本hbase> create 't1', {NAME => 'f1', VERSIONS => 1}# MIN_VERSIONS:最小版本hbase> create 't1', {NAME => 'f1', MIN_VERSIONS => 0}# COMPRESSION:压缩(记得加入压缩依赖包),在hbase-site-xml设置:hbase.regionserver.codecs -> SNAPPYhbase> create 't1', {NAME => 'f1',COMPRESSION => 'SNAPPY'}# blockingStoreFiles:阻塞大小hbase> create 't1', {NAME => 'f1',CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}## 创建表,SPLITS预分区方式#按ROWKEY分区hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']#分区信息写在文件中,分区信息文件在本地hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'#十六进制方式创建预分区hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
分区设计:以区域设置region。如区域码0401代表广东广州。区域码可以由电话号码获取。
##分区信息这里应该写入文件中#hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'hbase> create 'order:tel_order', 'info', SPLITS => ['0401', '0402', '0403', '0404']
ROWKEY设计:主表,区域码+电话号码+通话时间。
针对查询某个号码某个时间段的通话记录的需求。获取到电话号码和要查询的时间段可以得到:区域码+电话号码+开始时间->startkey区域码+电话号码+结束时间->endkey调用Hbase JAVA API 查询/*** 检索数据** @param:starRow,开始rowkey* @param:endRow,结束rowkey* */public Map<String, List<Map<String, Object>>> scanData(byte[] starRow,byte[] endRow) throws Exception {scan.setStartRow(starRow);scan.setStopRow(endRow);return scanData(scan);}
索引表ROWKEY设计:保证ROWKEY的唯一对应到主表,列的值是主表的ROWKEY。
在此输入正文