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);

 

posted on 2017-10-20 14:25  cxhfuujust  阅读(176)  评论(0编辑  收藏  举报

导航