当前位置: 首页 > backend >正文

hbase shell的常用命令

一、hbase shell的基础命令

# 客户端登录
[root@Cloud-Hadoop-NN-02 hbase]$ ./bin/hbase shell# 查看所有表
hbase> list### 创建数据表student,包含Sname、Ssex、Sage、Sdept、course列族/列
### 说明:列族不指定列名时,列族可以直接成为列名,从下面的数据插入可以看出 !!!
hbase> create 'student','Sname','Ssex','Sage','Sdept','course'# 描述表信息
hbase> describe 'student'
Table student is ENABLED                                                                                                                                                                       
student                                                                                                                                                                                        
COLUMN FAMILIES DESCRIPTION                                                                                                                                                                    
{NAME => 'Sage', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                                                               {NAME => 'Sdept', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSI
ONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                                                              {NAME => 'Sname', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSI
ONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                                                              {NAME => 'Ssex', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIO
NS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                                                               {NAME => 'course', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERS
IONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                                                             
5 row(s)# 插入数据表student:Sname:xing='Shen'
hbase> put 'student','10001','Sname:xing','Shen'
hbase> put 'student','10001','Sname:ming','HY'
hbase> put 'student','10001','Ssex',1# 查询数据表student:rowkey='10001'
hbase> get 'student','10001'
Took 0.0052 seconds                                                                                                                                                                            
hbase:014:0> get 'student','10001'
COLUMN                                           CELL                                                                                                                                          Sname:ming                                      timestamp=2025-05-14T16:42:55.882, value=HY                                                                                                   Sname:xing                                      timestamp=2025-05-14T16:42:43.429, value=Shen                                                                                                 Ssex:                                           timestamp=2025-05-14T16:48:28.510, value=1                                                                                                    
1 row(s)
Took 0.0161 seconds    # 查询数据表student:全部数据
hbase> scan 'student'
ROW                                              COLUMN+CELL                                                                                                                                   10001                                           column=Sname:ming, timestamp=2025-05-14T16:42:55.882, value=HY                                                                                10001                                           column=Sname:xing, timestamp=2025-05-14T16:42:43.429, value=Shen                                                                              10001                                           column=Ssex:, timestamp=2025-05-14T16:48:28.510, value=1                                                                                      
1 row(s)
Took 0.0135 seconds    ### 创建数据表scores:包含grade,course字段
hbase> create 'scores','grade','course'# 插入数据表scores:rowkey=zhangsan01 ......
hbase> put 'scores','zhangsan01','grade:','101'
hbase> put 'scores','zhangsan01','course:art','90'
hbase> put 'scores','zhangsan01','course:math','99',1498003561726  
#这里手动设置时间戳的时候一定不能大于当前系统时间,否则无法删除该数据。这里手动设置数据是为了下面的DependentColumnFilter过滤器试验。可以查看一下插入第一条数据的时间戳,再插入第二条数据的时间戳为第一条数据的时间戳
hbase> put 'scores','zhangsan02','grade:','102',1498003601365
hbase> put 'scores','zhangsan02','course:art','90'
hbase> put 'scores','zhangsan02','course:math','66',1498003561726
hbase> put 'scores','lisi01','grade:','201',1498003561726
hbase> put 'scores','lisi01','course:art','89'
hbase> put 'scores','lisi01','course:math','89',1498003561726# 查询两个rowkey之间的数据
hbase> scan 'scores',{STARTROW=>'zhangsan01',STOPROW=>'zhangsan02'}
ROW                                                          COLUMN+CELL                                                                                                                                                                     zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            zhangsan01                                                  column=course:math, timestamp=1498003561726, value=99                                                                                                                           zhangsan01                                                  column=grade:, timestamp=1498003593575, value=101                                                                                                                               
1 row(s) in 0.0140 seconds# 根据列名查询
hbase> scan 'scores',{COLUMNS=>'course:art'}
ROW                                                          COLUMN+CELL                                                                                                                                                                     lisi01                                                      column=course:art, timestamp=1498003655021, value=89                                                                                                                            zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            zhangsan02                                                  column=course:art, timestamp=1498003601365, value=90                                                                                                                            
3 row(s) in 0.0120 seconds# 查询两个rowkey之间&根据列名来查询
hbase> scan 'scores',{COLUMNS=>'course:art',STARTROW=>'zhangsan01',STOPROW=>'zhangsan02'}
ROW                                                          COLUMN+CELL                                                                                                                                                                     zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            
1 row(s) in 0.0110 seconds# 限制查找条数
hbase> scan 'scores',{LIMIT=>1}
ROW                                                          COLUMN+CELL                                                                                                                                                                     zhangsan01                                                  column=course:art, timestamp=1498003561726, value=90                                                                                                                            zhangsan01                                                  column=course:math, timestamp=1498003561726, value=99                                                                                                                           zhangsan01                                                  column=grade:, timestamp=1498003593575, value=101                                                                                                                               
1 row(s) in 0.0140 seconds# 查询时序数据
hbase> get 'pfme','dh_p_030_13030006@_@1747090800@_@'
# 查询时序数据
hbase> get 'pfme','dh_p_030_13030006@_@1747130400@_@FF-67-12-02-10-6A'# 客户端退出
hbase> exit

二、hbase shell 实现rowkey的模糊查询

# 前缀匹配法
#查询以"2025"开头的rowkey,左闭右开区间(性能较高)
hbase> scan 'table_name', {STARTROW => '2025', STOPROW => '2025z'}# 正则表达式过滤
#查询包含"123"的rowkey(性能较低,全表扫描时慎用,建议配合STARTROW/STOPROW缩小范围)
hbase> scan 'table_name', {FILTER => "RowFilter(=, 'regexstring:.*123.*')"}# 子串匹配优化方案
#查询中间含"123"的rowkey(需预知固定长度),适用于已知字段固定位置时的精准匹配
hbase> scan 'table_name', { STARTROW => '000123', STOPROW => '999123z', FILTER => "ValueFilter(=, 'substring:123')"}# 分页模糊查询
#分页查询含"123"的rowkey(每页10条),通过STARTROW参数实现翻页功能
hbase> scan 'table_name', { FILTER => "PageFilter(10) AND RowFilter(=, 'substring:123')"}#eg: 查询DH专业的ct-tsdb
scan 'pfme', {STARTROW => 'dh_p_030_13030006@_@1747206000', STOPROW => 'dh_p_030_13030006@_@1747206000z'}

三、hbase shell 实现列值的模糊查询

#查询列族cf和列名c1中以123开头的所有行
hbase> scan 'table_name', {COLUMNS => ['cf:c1'], FILTER => "(PrefixFilter('123'))"}#查询指定的列值中包含"123"的所有行
hbase> scan 'table_name', {COLUMNS => ['cf1:c1', 'cf2:c2'], FILTER => "ValueFilter(=, regexstring:'.*123.*')"}

参考文档:https://blog.csdn.net/m0_37739193/article/details/73615016#

http://www.xdnf.cn/news/6063.html

相关文章:

  • 双目云台摄像机:双摄安防功能全方位
  • Java运行原理分析
  • LeetCode 热题 100 114. 二叉树展开为链表
  • Spring的bean的生命周期?
  • 【机器学习】支持向量回归(SVR)从入门到实战:原理、实现与优化指南
  • 各大编程语言基本语法区别
  • 游戏引擎学习第279天:将实体存储移入世界区块
  • 为什么 Linux 上默认没有 host.docker.internal
  • 【内网渗透】——NTML以及Hash Relay
  • MySQL Explain 中 Type 与 Extra 字段详解
  • MySQL 服务器配置和管理(上)
  • 监听用户切换浏览器标签页,切换回页面刷新页面
  • 代码随想录算法训练营第60期第三十五天打卡
  • 嵌入式自学第二十天(5.13)
  • AIStarter新功能上线:模型管理与创作者收益系统全面升级,助力AI开发效率提升
  • 函数定义、 异常处理、 迭代器协议、内置函数、返回值
  • WiFi密码查看器打开软件自动获取数据
  • 通用Agent如何评估效果:智能体评测方案AgentCLUE-General(Manus暂时领先)
  • 人形机器人的 9 个分岔口
  • 图灵爬虫练习平台 第十四题 逆向
  • 一款倒计时结束强制关闭浏览器的插件
  • 可视化图解算法38:重建二叉树
  • C++标准流详解:cin/cout的绑定机制与cerr/clog的缓冲差异
  • Spark集群搭建-Standalone
  • 芯片:金线的作用
  • 关于 ast: Babel AST 全类型总览
  • 在Java中实现Parcelable接口和Serializable接口有什么区别?
  • trame实现双视图(返场版)
  • MySQL 日期计算方法 date_sub()、date_add()、datediff() 详解-文中有示例帮助理解
  • java基础-泛型