0
点赞
收藏
分享

微信扫一扫

HBase实战案例一之基本Shell命令

RJ_Hwang 2022-01-28 阅读 64


HBase实战案例一之基本Shell命令

1 示例1

  • ​create​​ 操作
hbase(main):010:0> create 'telecom','cf'
0 row(s) in 1.3080 seconds

=> Hbase::Table - telecom
  • ​desc​​ 操作
hbase(main):004:0> desc 'telecom'
Table telecom is ENABLED
telecom
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLO
CKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.0350 seconds

解析显示结果:

​Table telecom is ENABLED​​:telecom 表可用

​telecom​​: 表名

​COLUMN FAMILIES DESCRIPTION​​:列族描述

​{...}​​:表示列族的详细特征。其中主要的字段意义如下:

​name​​ :列族名称

​bloomfilter​​ :布隆过滤器

  • ​put​​ 操作【仅提供两条】
put 'telecom', '001','cf:duration', 2046
put 'telecom', '002','cf:duration', 782
  • ​scan​​ 操作
hbase(main):014:0> scan 'telecom'
ROW COLUMN+CELL
001 column=cf:duration, timestamp=1542164106661, value=2046
002 column=cf:duration, timestamp=1542164111651, value=782
2 row(s) in 0.0250 seconds
  • ​get​​ 操作
hbase(main):026:0> get 'telecom','001'
COLUMN CELL
cf:duration timestamp=1542164106661, value=2046
1 row(s) in 0.2040 seconds

hbase(main):027:0> get 'telecom','0001'
COLUMN CELL
0 row(s) in 0.0060 seconds
hbase(main):031:0> get 'telecom','001','cf:duration'
COLUMN CELL
cf:duration timestamp=1542164106661, value=2046
1 row(s) in 0.0170 seconds

这个时候若再执行如下操作:

hbase(main):032:0> put 'telecom', '001','cf:test', 1024
0 row(s) in 0.0350 seconds

hbase(main):033:0> scan 'telecom'
ROW COLUMN+CELL
001 column=cf:duration, timestamp=1542164106661, value=2046
001 column=cf:test, timestamp=1542164576852, value=1024
002 column=cf:duration, timestamp=1542164111651, value=782
2 row(s) in 0.0150 seconds
hbase(main):034:0> get 'telecom','001','cf:test'
COLUMN CELL
cf:test timestamp=1542164576852, value=1024
1 row(s) in 0.0110 seconds
  • ​count​​ 操作
hbase(main):006:0> count 'telecom'
2 row(s) in 0.6030 seconds

=> 2

上面这个​​count 'student'​​​的功能就是查找​​student​​表中不同rowKey的行数。

  • ​disable​​ 操作
hbase(main):044:0> disable 'telecom'
0 row(s) in 2.2880 seconds

若此时,还执行扫全表操作,则会报错

hbase(main):045:0> scan 'telecom'
ROW COLUMN+CELL

ERROR: telecom is disabled.
  • ​enable​​ 操作
hbase(main):046:0> enable 'telecom'
0 row(s) in 1.2890 seconds

enable 的操作是使表重新回到可用状态。

  • ​delete​​ 操作
hbase(main):046:0> enable 'telecom'
0 row(s) in 1.2890 seconds

hbase(main):047:0> scan 'telecom'
ROW COLUMN+CELL
001 column=cf:duration, timestamp=1542164106661, value=2046
001 column=cf:test, timestamp=1542164576852, value=1024
002 column=cf:duration, timestamp=1542164111651, value=782
2 row(s) in 0.0160 seconds
deleteall 'telecom','001'

上述的操作是删除​​telecom​​表中的rowKey = 0001的所有数据

hbase(main):049:0> scan 'telecom'
ROW COLUMN+CELL
002 column=cf:duration, timestamp=1542164111651, value=782
1 row(s) in 0.0060 seconds
  • ​drop​​​ 操作
    drop表之前,需要先将表diable掉。
hbase(main):050:0> disable 'telecom'
0 row(s) in 2.2790 seconds

hbase(main):051:0> drop 'telecom'
0 row(s) in 1.2360 seconds
hbase(main):053:0> list 'telecom'
TABLE
0 row(s) in 0.0080 seconds

=> []

再次查看表时,发现表已不存在。

2. 注

  • 如何使用命令查看hbase集群节点的状态?
hbase(main):060:0> status
1 active master, 0 backup masters, 3 servers, 0 dead, 2.6667 average load

  • 针对上述的put操作语句,会得到一个hbase表,但是如果将这个hbase表用行列的形式展现出来,会是什么样子呢?如下图所示:
    HBase实战案例一之基本Shell命令_shell命令
  • 如果需要在扫描表的时候指定扫描区间,如何操作?

3. 参考文章

  • ​​http://hbase.apache.org/book.html#shell_exercises​​


举报

相关推荐

0 条评论