hbase 命令

运行:hbase shell

-----------------------------------------hbase namespace-----------------------------------------

#创建命名空间
create_namespace 'test1'

#展示所有命名空间
list_namespace

#删除命名空间,The namespace must be empty.
drop_namespace 'test1'

-----------------------------------------hbase table-----------------------------------------

#列出hbase中所有表

list

#创建一张表,指定版本号为3
create 'hbase_test:teacher1',{NAME=>'baseinfo',VERSIONS=>3},{NAME=>'extrainfo',VERSIONS=>5}

create 'test1:student1',{NAME=>'baseinfo',VERSIONS=>3},{NAME=>'extrainfo',VERSIONS => 3}

#创建表,预定义分区,在rowkey为0<= <10 10<= 20 20<= 30
create 'hbase_test:teacher2', {NAME=>'baseinfo',VERSIONS=>3}, SPLITS => ['10', '20', '30', '40']

put 'hbase_test:teacher3','2000009','baseinfo:name','zhangsan'


#创建表,分区标准在文件中,如果rowkey以0001等开头,进行分区使用| 或者 ~ 帮助划分rowkey区域
create 'hbase_test:teacher3', 'baseinfo', {SPLITS_FILE => 'split1.txt'}

#使用HexStringSplit算法进行分区,分成10个region,适合散列字符不包含中文
create 'hbase_test:teacher4', 'baseinfo', {NUMREGIONS => 10, SPLITALGO => 'HexStringSplit'}

#使用UniformSplit算法进行分区,rowkey可以包含中文
create 'hbase_test:teacher5', 'baseinfo', {NUMREGIONS => 5, SPLITALGO => 'UniformSplit'}

#create 返回引用值
t1 = create 't1', 'f1'

#修改表结构增加列族
alter 'test1:student5', {NAME => 'extrainfo', IN_MEMORY => true}, {NAME => 'secret', VERSIONS => 5}

#修改表结构删除列族
alter 'hbase_test:teacher5', { NAME => 'baseinfo', METHOD => 'delete'}


#插入数据
put 't','r','cf:q','v','t'
put 'test1:student5','100000000','baseinfo:name','zhao'

#插入指定timestamp
put 'hbase_test:teacher5','100000000','extrainfo:salary','5000',1488888888888

put 'hbase_test:teacher2','10001','baseinfo:name','briup'
put 'hbase_test:teacher2','20001','baseinfo:name','qian'
put 'hbase_test:teacher2','30001','baseinfo:name','sun'

#获得某一个特定值
put 'hbase_test:teacher2','10001','baseinfo:name','briup1'
put 'hbase_test:teacher2','10001','baseinfo:name','briup2'
put 'hbase_test:teacher2','10001','baseinfo:name','briup3'
put 'hbase_test:teacher2','10001','baseinfo:name','briup4'
put 'hbase_test:teacher2','10001','baseinfo:name','briup5' 1488888888888
put 'hbase_test:teacher2','10001','baseinfo:name','briup6' 1503200888088

get 'hbase_test:teacher2','10001','baseinfo:name'

#获得前5个版本的数据
get 'hbase_test:teacher2','10001',{COLUMN=>'baseinfo:name',VERSIONS=>5}

#获得某个时间段数据,不一定是时间最新的数据
get 'hbase_test:teacher2', '10001', {TIMERANGE => [1479371084728, 1479373228331]}

#scan 扫描某张表
scan 'test1:teacher2'

#scan 扫描 表中某一列
scan 'test1:student5',{COLUMNS=>'baseinfo:name'}

#scan 使用limit 进行行数限制
scan 'test1:student5',{COLUMNS=>'baseinfo:name',LIMIT=>2}

#scan 指定从某一行开始扫描
scan 'hbase_test:teacher2',{COLUMNS=>'baseinfo:name',LIMIT=>2,STARTROW=>'20001'}

 

#scan 扫描所有版本
scan 'hbase_test:teacher2',{VERSIONS=>5}

#scan 超出版本限制也能访问到
scan 'hbase_test:teacher2',{VERSIONS=>5,RAW=>true}

#scan 使用过滤器 行健前缀过滤器,只有这一个有属性
scan 'hbase_test:teacher2', {ROWPREFIXFILTER => '10'}


#scan 使用空值行健过滤器,只返回行健
scan 'hbase_test:teacher2',{FILTER=>'KeyOnlyFilter()'}

#scan 使用行健过滤器,binary: 帮助数据类型转化
scan 'hbase_test:teacher2',{FILTER =>"RowFilter (!=,'binary:10001')"}

#scan 使用列名过滤器
scan 'test1:student5',{FILTER =>"QualifierFilter (>=,'binary:baseinfo:name')"}

#scan 使用子串过滤器
scan 'test1:student5',{FILTER =>"ValueFilter (=,'binary:zhao')"}

#列名前缀过滤器
scan 'test1:student5',{FILTER =>"ColumnPrefixFilter ('name')"}

#scan 使用多种过滤器进行条件结合
scan 'hbase_test:teacher2',{FILTER =>"(ValueFilter (=,'binary:hello')) OR (RowFilter (>,'binary:10'))"}

#scan 使用page过滤器,限制每页展示数量
scan 'hbase_test:teacher2',{FILTER =>org.apache.hadoop.hbase.filter.PageFilter.new(2)}


#disable 某张表
disable 'test1:student5'

#删除某张表
drop 'hbase_test:teacher2'


#大合并 hfile
major_compact 'hbase_test:teacher2'

小合并


#移动region move 'ENCODED_REGIONNAME', 'SERVER_NAME'
#第一个参数指的是region最后一部分编号(逗号分隔每部分)
move 'a39dc69bd00d19e556ae17e4aeb1ebe1','datanode02,16020,1479354142616'

a39dc69bd00d19e556ae17e4aeb1ebe1

 

 

//行过滤器
// 1 行健范围
ByteArrayComparable com1 = new BinaryComparator(Bytes.toBytes("briup004"));
RowFilter rf1 = new RowFilter(CompareOp.LESS, com1);
// 2 行健子串范围
ByteArrayComparable com2 = new SubstringComparator("007");
RowFilter rf2 = new RowFilter(CompareOp.EQUAL, com2);
// 3 某个列标示符的值范围
SingleColumnValueFilter scf1 = new SingleColumnValueFilter
(Bytes.toBytes("infos"), Bytes.toBytes("name"), CompareOp.LESS_OR_EQUAL, Bytes.toBytes("李狗蛋003"));
// 4 匹配正则表达式
ByteArrayComparable com3 = new SubstringComparator("test.");
SingleColumnValueFilter scf2 = new SingleColumnValueFilter
(Bytes.toBytes("infos"), Bytes.toBytes("name"), CompareOp.EQUAL,com3);
// 5 匹配子串 不区分大小写
ByteArrayComparable com4 = new SubstringComparator("te");
SingleColumnValueFilter scf3 = new SingleColumnValueFilter
(Bytes.toBytes("infos"), Bytes.toBytes("name"), CompareOp.EQUAL,com4);

 

转载于:https://www.cnblogs.com/cxhfuujust/p/7699315.html

<think>好的,我现在需要帮助用户了解HBase相关的命令列表及用法。首先,用户明确提到了HBase命令,并且引用了多个相关的资料,我需要仔细查看这些引用内容,提取有用的信息来构建回答。 首先,引用[1]提到HBase Shell是官方提供的命令集,用户可以通过环境变量配置后,在命令行输入hbase shell进入。这是一个重要的起点,需要首先说明如何启动HBase Shell。引用[2]和[3]进一步补充了HBase的基本概念和操作模式,比如单机、伪分布式和完全分布式模式,这可能对用户理解命令的使用环境有帮助,但用户主要关注的是命令列表,所以可能需要简要提及环境。 接下来,引用[3]详细列出了基本操作、DML操作以及删除与版本管理的内容。基本操作包括启动HBase、命名空间操作和表操作命令。DML部分涉及数据写入和读取。引用[4]和[5]提供了更多具体的命令,例如查看表列表使用!tables,以及列出命名空间下的表list_namespace_tables。这些具体的命令需要分类整理,方便用户查找。 用户的需求是命令列表及用法,因此我需要将命令按功能分类,比如基本命令、命名空间管理、表操作、数据操作(DML)、删除与版本控制等。同时,需要注意每个命令的格式和示例,例如创建命名空间、创建表时需要指定列族等。 需要检查是否有遗漏的命令,比如是否提到了Java API操作,但用户主要关注Shell命令,所以可能不需要深入Java部分。另外,确保每个命令的语法正确,比如使用单引号还是双引号,参数的正确顺序等。 另外,用户提供的引用中有一些重复的信息,需要整合,避免重复。例如,启动HBase在引用[2]和[3]都有提到,但需要统一说明。同时,注意命令的大小写,HBase Shell命令通常使用小写,但某些参数可能需要大写,比如命名空间名称。 最后,按照用户的要求,生成相关问题,这些问题应该围绕HBase命令的扩展使用、优化和应用场景,例如如何优化表结构,如何备份数据等。 现在需要组织这些信息,确保结构清晰,每个部分有明确的标题,命令用代码块表示,符合用户要求的格式。同时,正确引用来源,在适当的位置添加引用标识,如启动HBase Shell的部分引用[^1],创建命名空间引用[^5]等。</think>### HBase 常用命令列表及用法 #### 1. 启动HBase Shell 配置环境变量后,在命令行输入以下命令进入交互式命令行环境: ```bash hbase shell ``` [^1] --- #### 2. 命名空间操作 - **查看所有命名空间** ```hbase list_namespace ``` - **创建命名空间** ```hbase create_namespace 'ns1' ``` - **删除命名空间**(需先删除内部所有表) ```hbase drop_namespace 'ns1' ``` [^5] --- #### 3. 表操作 - **查看所有表** ```hbase list ``` 或 ```hbase !tables # 部分版本支持 ``` [^4] - **创建表**(需指定列族) ```hbase create 'ns1:table1', 'cf1', 'cf2' ``` 其中`ns1`为命名空间,`cf1`为列族名称。 - **查看表结构** ```hbase describe 'ns1:table1' ``` - **删除表**(需先禁用表) ```hbase disable 'ns1:table1' drop 'ns1:table1' ``` --- #### 4. 数据操作(DML) - **写入数据** ```hbase put 'ns1:table1', 'row1', 'cf1:name', 'Alice' ``` 参数依次为:表名、行键、列族:列名、值。 - **读取单行数据** ```hbase get 'ns1:table1', 'row1' ``` - **扫描全表数据** ```hbase scan 'ns1:table1' ``` - **按条件扫描**(如限定版本数) ```hbase scan 'ns1:table1', {VERSIONS => 3} ``` [^3] --- #### 5. 删除与版本控制 - **删除特定列数据** ```hbase delete 'ns1:table1', 'row1', 'cf1:name' ``` - **删除整行数据** ```hbase deleteall 'ns1:table1', 'row1' ``` - **查看历史版本数据** HBase默认保存多个版本数据,通过`VERSIONS`参数指定存储的版本数: ```hbase alter 'ns1:table1', {NAME => 'cf1', VERSIONS => 5} ``` --- #### 6. 状态与调试 - **检查集群状态** ```hbase status ``` - **查看表是否启用** ```hbase is_enabled 'ns1:table1' ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值