HBase Shell操作命令
- DDL操作命令
- DML操作命令
HBase Shell操作包括:DDL操作和DML操作。
DDL操作命令
HBase Shell命令 | 功能描述 |
---|---|
list | 列出HBase中的所有表 |
create | 创建一张表 |
describe | 列出表的详细信息 |
alter | 修改表的列族 |
disable | 禁用表,使表无效 |
enable | 启用表,使表有效 |
drop | 删除一张表 |
exists | 判断表是否存在 |
具体操作如下:
# 查詢表信息hbase(main):003:0> list# 創建表空間hbase(main):004:0> create_namespace \'cjh\'# 查看表空間hbase(main):006:0> list_namespace# 刪除表空間hbase(main):008:0> drop_namespace \'cjh\'# 在cjh中創建表hbase(main):011:0> create \'cjh:student\',\'baseinfo\', \'schoolinfo\'# 查看指定表空間下的表hbase(main):013:0> list_namespace_tables \'cjh\'# 查看描述表信息hbase(main):014:0> describe \'cjh:student\'# 查看指定表是否不可用hbase(main):015:0> is_disabled \'cjh:student\'false0 row(s) in 0.0200 seconds# 查看指定表是否可用hbase(main):016:0> is_enabled \'cjh:student\'true0 row(s) in 0.0100 seconds# 禁用表hbase(main):018:0> disable \'cjh:student\'# 启用表hbase(main):020:0> enable \'cjh:student\'# 删除表前必须要将表disable(禁用),否则删除会失败hbase(main):022:0> drop \'cjh:student\'ERROR: Table cjh:student is enabled. Disable it first.# 修改表,添加列族hbase(main):023:0> alter \'cjh:student\',\'teacherinfo\'# 查看表详情hbase(main):024:0> desc \'cjh:student\'# 修改表,删除列族hbase(main):025:0> alter \'cjh:student\', NAME=>\'teacherinfo\', METHOD=>\'delete\'修改默认的存贮版本数hbase(main):040:0> alter \'cjh:student\',NAME=>\'baseinfo\',VERSIONS=>3
DML操作命令
HBase Shell命令 | 功能描述 |
---|---|
put | 向指定的单元添加值 |
scan | 通过扫描表来获取数据 |
get | 获取行或者单元的值 |
count | 统计表中行的数量,一个行键为一行 |
delete | 删除指定对象的值 |
deleteall | 删除整行 |
truncate | 清空表的数据 |
具体操作如下:
# 插入数据hbase(main):031:0> put \'cjh:student\',\'rowkey\', \'baseinfo:name\',\'lijia\'0 row(s) in 0.0540 secondshbase(main):032:0> scan \'cjh:student\'ROW COLUMN+CELLrowkey column=baseinfo:name, timestamp=1586320330442, value=lijia1 row(s) in 0.0170 secondshbase(main):033:0> put \'cjh:student\',\'rowkey\',\'baseinfo:name\',\'cjh\'0 row(s) in 0.0070 secondshbase(main):034:0> scan \'cjh:student\'ROW COLUMN+CELLrowkey column=baseinfo:name, timestamp=1586320401611, value=cjh1 row(s) in 0.0050 secondshbase(main):035:0> put \'cjh:student\',\'rowkey\',\'baseinfo:age\',\'30\'0 row(s) in 0.0040 secondshbase(main):036:0> scan \'cjh:student\'ROW COLUMN+CELLrowkey column=baseinfo:age, timestamp=1586320442439, value=30rowkey column=baseinfo:name, timestamp=1586320401611, value=cjh1 row(s) in 0.0050 secondshbase(main):037:0> put \'cjh:student\',\'rowkey\',\'baseinfo:birthday\',\'1986-10-1\'0 row(s) in 0.0040 secondshbase(main):038:0> scan \'cjh:student\'ROW COLUMN+CELLrowkey column=baseinfo:age, timestamp=1586320442439, value=30rowkey column=baseinfo:birthday, timestamp=1586320512382, value=1986-10-1rowkey column=baseinfo:name, timestamp=1586320401611, value=cjh1 row(s) in 0.0150 seconds# 删除列族中的指定列hbase(main):028:0> delete \'cjh:student\',\'rowkey4\',\'schoolinfo:name\'# 删除一整行数据hbase(main):032:0> delete \'cjh:student\', \'rowkey4\'# 查询指定行‘rowkey2’的信息hbase(main):035:0> get \'cjh:student\',\'rowkey2\'COLUMN CELLbaseinfo:age timestamp=1586397540495, value=8baseinfo:birthday timestamp=1586397559259, value=2012-5-1baseinfo:name timestamp=1586397492894, value=antschoolinfo:location timestamp=1586397647560, value=chahaerluschoolinfo:name timestamp=1586397629168, value=chahaerluxiaoxue# 查询指定行‘rowkey2’的baseinfo列族的信息hbase(main):036:0> get \'cjh:student\',\'rowkey2\',\'baseinfo\'COLUMN CELLbaseinfo:age timestamp=1586397540495, value=8baseinfo:birthday timestamp=1586397559259, value=2012-5-1baseinfo:name timestamp=1586397492894, value=ant3 row(s) in 0.0030 seconds# 查询指定行‘rowkey2’的baseinfo列族的‘name’列信息hbase(main):037:0> get \'cjh:student\',\'rowkey2\',\'baseinfo:name\'COLUMN CELLbaseinfo:name timestamp=1586397492894, value=ant1 row(s) in 0.0050 seconds# 全表扫描hbase(main):038:0> scan \'cjh:student\'# 全表扫描,baseinfo列族的信息hbase(main):039:0> scan \'cjh:student\', COLUMN=>\'baseinfo# 全表扫描,baseinfo列族的name列信息hbase(main):040:0> scan \'cjh:student\', COLUMN=>\'baseinfo:name\'ROW COLUMN+CELLrowkey column=baseinfo:name, timestamp=1586320401611, value=cjhrowkey2 column=baseinfo:name, timestamp=1586397492894, value=antrowkey3 column=baseinfo:name, timestamp=1586397737697, value=xiu3 row(s) in 0.0050 seconds# 全表扫描,baseinfo列族的name列信息, 从rowkey2开始hbase(main):041:0> scan \'cjh:student\', COLUMN=>\'baseinfo:name\', STARTROW=> \'rowkey2\'ROW COLUMN+CELLrowkey2 column=baseinfo:name, timestamp=1586397492894, value=antrowkey3 column=baseinfo:name, timestamp=1586397737697, value=xiu2 row(s) in 0.0100 seconds# 全表扫描,baseinfo列族的name列信息, 从rowkey开始,到rowkey3(不包含)结束base(main):047:0> scan \'cjh:student\', COLUMN=>\'baseinfo:name\', STARTROW=> \'rowkey\',STOPROW=>\'rowkey3\'# 全表扫描,baseinfo列族的name列信息, 从rowkey开始,到rowkey3(不包含)结束 LIMIT限制hbase(main):049:0> scan \'cjh:student\', COLUMN=>\'baseinfo:name\', STARTROW=> \'rowkey\',STOPROW=>\'rowkey3\',LIMIT=>2ROW COLUMN+CELLrowkey column=baseinfo:name, timestamp=1586320401611, value=cjhrowkey2 column=baseinfo:name, timestamp=1586397492894, value=ant
# 值等于8的hbase(main):051:0> scan \'cjh:student\', FILTER=>\"ValueFilter(=,\'binary:8\')\"ROW COLUMN+CELLrowkey2 column=baseinfo:age, timestamp=1586397540495, value=81 row(s) in 0.0210 seconds# 值等于1986-11-25的hbase(main):054:0> scan \'cjh:student\', FILTER=>\"ValueFilter(=,\'binary:1986-11-25\')\"ROW COLUMN+CELLrowkey3 column=baseinfo:birthday, timestamp=1586397781809, value=1986-11-251 row(s) in 0.0050 seconds# 值包含(模糊查询)hbase(main):056:0> scan \'cjh:student\', FILTER=>\"ValueFilter(=,\'substring:g\')\"ROW COLUMN+CELLrowkey column=baseinfo:name, timestamp=1586320401611, value=cjhrowkey3 column=schoolinfo:location, timestamp=1586397832076, value=qingliangmendajie2 row(s) in 0.0200 secondshbase(main):057:0> scan \'cjh:student\', FILTER=>\"ValueFilter(=,\'substring:1986\')\"ROW COLUMN+CELLrowkey column=baseinfo:birthday, timestamp=1586320512382, value=1986-10-1rowkey3 column=baseinfo:birthday, timestamp=1586397781809, value=1986-11-252 row(s) in 0.0100 seconds# 列前缀匹配hbase(main):058:0> scan \'cjh:student\',FILTER=>\"ColumnPrefixFilter(\'bir\')\"hbase(main):059:0> scan \'cjh:student\',FILTER=>\"ColumnPrefixFilter(\'na\')\"# 多过滤查询hbase(main):061:0> scan \'cjh:student\', FILTER=>\"ColumnPrefixFilter(\'na\') AND ValueFilter(=,\'substring:e\')\"hbase(main):063:0> scan \'cjh:student\', FILTER=>\"ColumnPrefixFilter(\'na\') AND (ValueFilter(=,\'substring:ee\') OR ValueFilter(=,\'substring:ue\'))\"# 对rowkey的前置过滤hbase(main):069:0> scan \'cjh:student\', FILTER=>\"PrefixFilter(\'row\')\"# 查找row中 包含2的rowkey信息hbase(main):071:0> scan \'cjh:student\',FILTER=>\"RowFilter(=,\'substring:2\')\"hbase(main):073:0> import org.apache.hadoop.hbase.filter.RowFilterhbase(main):074:0> import org.apache.hadoop.hbase.filter.RegexStringComparatorhbase(main):080:0> import org.apache.hadoop.hbase.filter.CompareFilterscan \'cjh:student\',FILTER=>RowFilter.new(CompareFilter::CompareOp.valueOf(\'EQUAL\'), RegexStringComparator.new(\'^row[\\w]*\\d\'))
# 从HDFS导入数据到HBase[root@lijia1 ~]# hdfs dfs -put ./hbase_import_data.csv /user/hbase(main):082:0> creat \'cjh:customer\',\'order\'[root@lijia1 ~]# hbase org.apache.hadoop.hbase.mapreduce.ImportTsv \\> -Dimporttsv.separator=, \\> -Dimporttsv.columns=\"HBASE_ROW_KEY,order:numb,order:date\" \\> cjh:customer /user/hbase_import_data.csv
ps:望多多支持,后续更新中。。。