查看版本
hbase(main):001:0> version
查看状态
hbase(main):002:0> status
帮助
hbase(main):006:0> help 'status'
hbase(main):006:0> help 'get'
hbase(main):007:0> help 'put'
查询所有的表空间(库)
hbase(main):008:0> list_namespace
查询指定表空间下的表
hbase(main):009:0> list_namespace_tables 'gree'
创建表空间
hbase(main):010:0> create_namespace 'kb15'
删除表空间
hbase(main):012:0> drop_namespace 'kb15'
在指定表空间下创建student表,指定列族 baseInfo schooleInfo
hbase(main):016:0> create 'kb15:student','baseInfo','schooleInfo'
查看表详情
hbase(main):017:0> describe 'kb15:student'
hbase(main):001:0> desc 'kb15:student'
启用、禁用; 查看表是否启用,是否禁用
hbase(main):018:0> is_enabled 'kb15:student'
true
0 row(s) in 0.0230 seconds
hbase(main):019:0> is_disabled 'kb15:student'
false
0 row(s) in 0.0130 seconds
hbase(main):020:0> disable 'kb15:student'
0 row(s) in 2.2670 seconds
hbase(main):021:0> is_disabled 'kb15:student'
true
0 row(s) in 0.0210 seconds
hbase(main):022:0> enable 'kb15:student'
0 row(s) in 1.2600 seconds
hbase(main):023:0> is_enabled 'kb15:student'
true
查看表是否存在
hbase(main):025:0> exists 'kb15:student1'
Table kb15:student1 does not exist
0 row(s) in 0.0110 seconds
hbase(main):026:0> exists 'kb15:student'
Table kb15:student does exist
0 row(s) in 0.0150 seconds
删除表(删除表之前,首先要禁用)
hbase(main):028:0> disable 'kb15:student'
0 row(s) in 2.2580 seconds
hbase(main):029:0> drop 'kb15:student'
0 row(s) in 1.2530 seconds
删除表空间前,要先把表空间内的表全部删除
hbase(main):032:0> list_namespace_tables 'gree'
TABLE
student
1 row(s) in 0.0050 seconds
hbase(main):033:0> is_enabled 'gree:student'
true
0 row(s) in 0.0190 seconds
hbase(main):034:0> disable 'gree:student'
0 row(s) in 2.2510 seconds
hbase(main):035:0> is_enabled 'gree:student'
false
0 row(s) in 0.0120 seconds
hbase(main):036:0> drop 'gree:student'
0 row(s) in 1.2530 seconds
hbase(main):037:0> drop_namespace 'gree'
0 row(s) in 0.0270 seconds
新增列族
hbase(main):041:0> alter 'kb15:student','teacherInfo'
删除列族
hbase(main):043:0> alter 'kb15:student',{NAME=>'teacherInfo',METHOD=>'delete'}
设置baseInfo,记录三个版本
hbase(main):047:0> alter 'kb15:student',{NAME=>'baseInfo',VERSIONS=>3}
查入数据
hbase(main):048:0> put 'kb15:student','rowkey1','baseInfo:name','tom'
hbase(main):049:0> put 'kb15:student','rowkey1','baseInfo:birthday','1984-02-10'
hbase(main):050:0> put 'kb15:student','rowkey1','baseInfo:age','38'
hbase(main):051:0> put 'kb15:student','rowkey1','schooleInfo:name','njzb'
hbase(main):052:0> put 'kb15:student','rowkey1','schooleInfo:location','andemen'
第二次Put baseInfo:name
hbase(main):055:0> put 'kb15:student','rowkey1','baseInfo:name','gree'
第三次Put baseInfo:name
hbase(main):057:0> put 'kb15:student','rowkey1','baseInfo:name','lijia'
hbase(main):060:0> put 'kb15:student','rowkey2','baseInfo:name','ant'
hbase(main):061:0> put 'kb15:student','rowkey2','baseInfo:age','10'
hbase(main):062:0> put 'kb15:student','rowkey2','baseInfo:birthday','2012-05-01'
hbase(main):063:0> put 'kb15:student','rowkey2','schooleInfo:name','cahaerluxiaoxue'
hbase(main):064:0> put 'kb15:student','rowkey2','schooleInfo:location','cahaerlu'
hbase(main):068:0> put 'kb15:student','rowkey3','baseInfo:name','xiu'
hbase(main):071:0> put 'kb15:student','rowkey3','baseInfo:age','36'
hbase(main):072:0> put 'kb15:student','rowkey3','baseInfo:birthday','1986-11-25'
hbase(main):073:0> put 'kb15:student','rowkey3','schooleInfo:name','ruisitang'
hbase(main):074:0> put 'kb15:student','rowkey3','schooleInfo:location','daqiaonanlu'
get查询
hbase(main):079:0> get 'kb15:student','rowkey1'
hbase(main):081:0> get 'kb15:student','rowkey2','baseInfo'
hbase(main):082:0> get 'kb15:student','rowkey2','schooleInfo'
hbase(main):083:0> get 'kb15:student','rowkey2','schooleInfo:name'
hbase(main):084:0> get 'kb15:student','rowkey2',{COLUMN=>'schooleInfo:name'}
全表扫描,条件过滤
hbase(main):076:0> scan 'kb15:student'
hbase(main):091:0> scan 'kb15:student',COLUMN=>'baseInfo'
hbase(main):092:0> scan 'kb15:student',{COLUMN=>'baseInfo'}
hbase(main):004:0> scan 'kb15:student',{COLUMN=>'baseInfo:name'}
hbase(main):005:0> scan 'kb15:student',{COLUMN=>'baseInfo:birthday'}
hbase(main):016:0> scan 'kb15:student',{COLUMN=>'baseInfo:name',STARTROW=>'rowkey1', STOPROW=>'rowkey4', VERSIONS=>3,LIMIT=>1}
删除指定列族下的列
hbase(main):022:0> delete 'kb15:student','rowkey4','baseInfo:age'
删除指定行 rowkey
hbase(main):023:0> get 'kb15:student','rowkey4'
条件过滤
value=38
hbase(main):029:0> scan 'kb15:student',FILTER=>"ValueFilter(=,'binary:38')"
ROW COLUMN+CELL
rowkey1 column=baseInfo:age, timestamp=1637545126111, value=38
value=lijia
hbase(main):030:0> scan 'kb15:student',FILTER=>"ValueFilter(=,'binary:lijia')"
ROW COLUMN+CELL
rowkey1 column=baseInfo:name, timestamp=1637545351672, value=lijia
value=1984-02-10
hbase(main):031:0> scan 'kb15:student',FILTER=>"ValueFilter(=,'binary:1984-02-10')"
ROW COLUMN+CELL
rowkey1 column=baseInfo:birthday, timestamp=1637545102591, value=1984-02-10
value包含 i
hbase(main):034:0> scan 'kb15:student',FILTER=>"ValueFilter(=,'substring:i')"
value包含 19
hbase(main):035:0> scan 'kb15:student',FILTER=>"ValueFilter(=,'substring:19')"
列名以birth开头
hbase(main):037:0> scan 'kb15:student',FILTER=>"ColumnPrefixFilter('birth')"
列名以birth开头 且 value中包含19的数据
hbase(main):038:0> scan 'kb15:student',FILTER=>"ColumnPrefixFilter('birth') AND ValueFilter(=,'substring:19')"
列名以birth开头 且 value中包含19或20的数据
hbase(main):040:0> scan 'kb15:student',FILTER=>"ColumnPrefixFilter('birth') AND (ValueFilter(=,'substring:19') OR ValueFilter(=,'substring:20')) "
过滤列(rowkey)
hbase(main):041:0> scan 'kb15:student',FILTER=>"PrefixFilter('row')"
hbase(main):047:0> scan 'kb15:student',FILTER=>"ValueFilter(=,'substring:1986')",STARTROW=>'rowkey2'
hbase(main):048:0> import org.apache.hadoop.hbase.filter.CompareFilter
=> Java::OrgApacheHadoopHbaseFilter::CompareFilter
hbase(main):049:0> import org.apache.hadoop.hbase.filter.SubstringComparator
=> Java::OrgApacheHadoopHbaseFilter::SubstringComparator
hbase(main):050:0> import org.apache.hadoop.hbase.filter.RowFilter
=> Java::OrgApacheHadoopHbaseFilter::RowFilter
hbase(main):051:0> import org.apache.hadoop.hbase.filter.RegexStringComparator
=> Java::OrgApacheHadoopHbaseFilter::RegexStringComparator
hbase(main):053:0> scan 'kb15:student', FILTER=>RowFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'),SubstringComparator.new('3'))
hbase(main):058:0> scan 'kb15:student', FILTER=>RowFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'),RegexStringComparator.new('^r[\w]*\d$'))