hbase shell 用法

175 阅读2分钟

hbase shell使用

hbase shell使用方法官方文档可参考 help.aliyun.com/document_de…

常用命令

表定义命令

指令含义
create创建hbase表
list列出所有的hbase表
disable禁用表
is_disabled验证表是否被禁用
enable启用一个表
is_enabled验证表是否被启用
describe提供表的描述
alter更改表结构
exists验证表是否存在
drop删除表

数据操作命令

指令含义
put插入数据
get取一行或者某个单元格的内容
delete删除表中的单元格值
deleteall删除给定行的所有单元格
scan扫描并返回表的数据
count计算表行数
truncate清空表数据,会丢失region分区
truncate_preserve清空表数据,region分区保留原样

常用命令如下:

# 查看表
-> list

# 创建一张表
->  create 'student','info'

# 存储/更新数据
->  put 'student','1001','info:name','Thomas'

# 查看存储的数据
->  scan 'student'

# 查看表结构
->  describe ‘student’

# 查看指定行数据
->  get 'student','1001','info:name'

# 删除某行数据
->  deleteall 'student','1001'

# 删除某行的某一列数据
->  delete 'student','1001','info:sex'

#清空表数据
->  truncate 'student'

#删除表
->  disable 'student'->  drop 'student'

#删除指定列族
->  alter 'student', 'delete' => 'info'
或
->  alter 'student',{NAME => 'info', METHOD => 'delete'}

二级索引

二级索引使用可参考:help.aliyun.com/document_de…

二级索引会创建一个以索引列为主键的表,若需要查询的列在索引列中不存在,则需要回查主表才能完成数据查询,因此,可以采用空间换时间的方式,将主表中的索引冗余在索引表中,避免再次回表查询。(类似于mysql的覆盖索引)

# 创建索引,索引列有2个,f1列族下的c2列,f2列族下的c3列。没有冗余列。
-> create_index 'idx1', 'dt', {INDEXED_COLUMNS => ['f1:c2', 'f2:c3']}

# 主表dt创建索引idx1,索引列有2个,f1列族下的c1列,冗余f2列族下的c2列。
-> create_index 'idx2', 'dt', {INDEXED_COLUMNS => ['f1:c1']}, {COVERED_COLUMNS => ['f2:c2']}

# idx3会冗余dt的所有列
-> create_index 'idx3', 'dt', {INDEXED_COLUMNS => ['f1:c3']}, {COVERED_COLUMNS => ['COVERED_ALL_COLUMNS']}

# 查看索引表schema
->  describe_index 'dt'

# 删除索引schema
->  offline_index 'idx1', 'dt'
->  remove_index 'idx1', 'dt'

目前已有数据时,建立索引需要同步的将已有数据同步到索引表中,因此会比较耗时。

全文索引

全文索引文档可参考:help.aliyun.com/document_de…

配置全文索引成功依赖于hbase增强版关联BDS集群(要求BDS不被其他业务使用),随后购买开通全文索引。

image.png