[关闭]
@awsekfozc 2016-01-22T22:55:57.000000Z 字数 1386 阅读 2204

Hbase create table

Hbase


1)创建表

  1. ##创建表,单个列簇
  2. hbase> create 't1', 'f1'
  3. ##创建表,多列簇
  4. hbase> create 't1', 'f1', 'f2'
  5. ##创建表,给列簇指定属性
  6. # NAME:列簇名
  7. hbase> create 't1', {NAME => 'f1'}
  8. # VERSIONS:版本
  9. hbase> create 't1', {NAME => 'f1', VERSIONS => 1}
  10. # MIN_VERSIONS:最小版本
  11. hbase> create 't1', {NAME => 'f1', MIN_VERSIONS => 0}
  12. # COMPRESSION:压缩(记得加入压缩依赖包),在hbase-site-xml设置:hbase.regionserver.codecs -> SNAPPY
  13. hbase> create 't1', {NAME => 'f1'COMPRESSION => 'SNAPPY'}
  14. # blockingStoreFiles:阻塞大小
  15. hbase> create 't1', {NAME => 'f1'CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
  16. ## 创建表,SPLITS预分区方式
  17. #按ROWKEY分区
  18. hbase> create 'ns1:t1', 'f1', SPLITS => ['10', '20', '30', '40']
  19. #分区信息写在文件中,分区信息文件在本地
  20. hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
  21. #十六进制方式创建预分区
  22. hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}

1)话单需求创建表

需求

伪代码

分区设计:以区域设置region。如区域码0401代表广东广州。区域码可以由电话号码获取。
  1. ##分区信息这里应该写入文件中
  2. #hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
  3. hbase> create 'order:tel_order', 'info', SPLITS => ['0401', '0402', '0403', '0404']
ROWKEY设计:主表,区域码+电话号码+通话时间。
  1. 针对查询某个号码某个时间段的通话记录的需求。获取到电话号码和要查询的时间段可以得到:
  2. 区域码+电话号码+开始时间->startkey
  3. 区域码+电话号码+结束时间->endkey
  4. 调用Hbase JAVA API 查询
  5. /**
  6. * 检索数据
  7. *
  8. * @param:starRow,开始rowkey
  9. * @param:endRow,结束rowkey
  10. * */
  11. public Map<String, List<Map<String, Object>>> scanData(byte[] starRow,
  12. byte[] endRow) throws Exception {
  13. scan.setStartRow(starRow);
  14. scan.setStopRow(endRow);
  15. return scanData(scan);
  16. }
索引表ROWKEY设计:保证ROWKEY的唯一对应到主表,列的值是主表的ROWKEY。

在此输入正文

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注