当前位置:   article > 正文

Hbase常见操作_hbase 控制每小时 hfile

hbase 控制每小时 hfile

进入hbase

hbase shell

可以查看命令如何使用

help 'put'

1、建表

  1. hbase(main):002:0> create 't1',{NAME=>'cf1'}
  2. Created table t1
  3. Took 1.0852 seconds
  4. hbase(main):022:0> create 'tb_t3','cf1','cf2','cf3'
  5. Created table tb_t3
  6. Took 1.2607 seconds
  7. hbase(main):024:0> create 'tb_t4',{NAME=>'cf1',VERSIONS=>'5'},'cf2','cf3'
  8. Created table tb_t4
  9. Took 2.2881 seconds

2、list 列出系统中所有的表,scan 查看表中的数据

  1. hbase(main):009:0> list
  2. TABLE
  3. t1
  4. 1 row(s)
  5. hbase(main):016:0> scan 't1'
  6. ROW COLUMN+CELL
  7. 0 row(s)

3、插入数据

  1. hbase(main):028:0> put 't1','rk001','cf1:uid','uid001'
  2. Took 0.0535 seconds
  3. hbase(main):029:0> scan 't1'
  4. ROW COLUMN+CELL
  5. rk001 column=cf1:uid, timestamp=1616312018455, value=uid001
  6. 1 row(s)
  7. Took 0.0206 seconds

4、添加修改删除列族

  1. 如果有就更新,没有就添加
  2. hbase(main):042:0> alter 't1' ,NAME=>'cf3',VERSIONS=>5
  3. Updating all regions with the new schema...
  4. 1/1 regions updated.
  5. Done.
  6. Took 2.6825 seconds
  7. --删除
  8. hbase(main):045:0> alter 't1' , 'delete'=>'cf3'
  9. Updating all regions with the new schema...
  10. 1/1 regions updated.
  11. Done.
  12. Took 2.6309 seconds
  13. hbase(main):047:0> alter 't1' ,NAME=>'cf3',VERSIONS=>5,METHOD=>'delete'
  14. Unknown argument ignored: VERSIONS
  15. Updating all regions with the new schema...
  16. 1/1 regions updated.

5、禁用表

disable 't1’

禁用的表不能对数据进行操作,不能put delete scan

可以alter 修改表结构

drop 表前要先禁用表

  1. hbase(main):006:0> disable 'tb_t4'
  2. Took 0.8404 seconds
  3. hbase(main):007:0> drop 'tb_t4'
  4. Took 0.2509 seconds

6、将表赋值给t ,然后通过t调用命令

  1. hbase(main):009:0> t=get_table 't1'
  2. Took 0.0003 seconds
  3. => Hbase::Table - t1
  4. hbase(main):010:0> t.scan
  5. ROW COLUMN+CELL
  6. rk001 column=cf1:age, timestamp=1616312073156, value=21
  7. rk001 column=cf1:name, timestamp=1616312045616, value=Alice
  8. rk001 column=cf1:uid, timestamp=1616312018455, value=uid001
  9. rk002 column=cf1:age, timestamp=1616312089155, value=23
  10. 2 row(s)
  11. Took 0.0124 seconds

7、查看数据文件

hbase hfile -p -f /hbase/data/default/t1/b2d5e5c725b9ff6e828c551f427e3df7/cf1/e1ada1f4d3a541b9872b40ac4673c422

region 名称:  b2d5e5c725b9ff6e828c551f427e3df7

8、按照指定的rk将一个region切割成两个region

  1. hbase(main):021:0> split 't1' ,'rk002'
  2. Took 0.2423 seconds
  3. hbase(main):023:0> list_regions 't1'
  4. SERVER_NAME | REGION_NAME | START_KEY | END_KEY | SIZE | REQ | LOCALITY |
  5. -------------------------- | -------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
  6. master,16020,1616308766374 | t1,,1616323524898.a0607dd00fd072b508ab32afdfbea9cb. | | rk002 | 0 | 0 | 1.0 |
  7. master,16020,1616308766374 | t1,rk002,1616323524898.047a3be11a8ecb734fd52e95ad87f9a2. | rk002 | | 0 | 0 | 1.0 |
  8. 2 rows
  9. Took 0.0406 seconds

9、建表时指定RK的规则预分region

  1. hbase(main):032:0> create 'tb_split','cf',SPLITS=>['e','l','o']
  2. Created table tb_split
  3. Took 2.3189 seconds
  4. hbase(main):033:0> list_regions 'tb_split'
  5. SERVER_NAME | REGION_NAME | START_KEY | END_KEY | SIZE | REQ | LOCALITY |
  6. -------------------------- | ---------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
  7. master,16020,1616308766374 | tb_split,,1616325215163.6107b005c0ae1fb7c32789cdab645581. | | e | 0 | 0 | 0.0 |
  8. master,16020,1616308766374 | tb_split,e,1616325215163.7c21f3deba399512f27b103300eec988. | e | l | 0 | 0 | 0.0 |
  9. master,16020,1616308766374 | tb_split,l,1616325215163.904de08df703786319acf279d9f93318. | l | o | 0 | 0 | 0.0 |
  10. master,16020,1616308766374 | tb_split,o,1616325215163.331c39b8f032b3141db87310008219ee. | o | | 0 | 0 | 0.0 |
  11. 4 rows

10、将内存中的数据写道HDFS中以hfile文件的格式存储

flush 'tb_split'

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号