HBase基础语法
文章目录
基本操作
进入 HBase 客户端命令行
[root@hadoop ~]# hbase shell
查看命名空间
hbase(main):001:0> list_namespace
查看命名空间下的表
hbase(main):002:0> list_namespace_tables 'default'
创建命名空间
hbase(main):003:0> create_namespace 'bigdata'
创建表
表中有两个列族 baseinfo, schoolinfo
hbase(main):005:0> create 'bigdata:student','baseinfo','schoolinfo'
查看表描述
hbase(main):006:0> desc 'bigdata:student'
# 或者
describe 'bigdata:student'
禁用/启用
# 禁用
hbase(main):008:0> disable 'bigdata:student'
#查看是否禁用
hbase(main):010:0> is_disabled 'bigdata:student'
#启用
hbase(main):012:0> enable 'bigdata:student'
#查看是否启用
hbase(main):013:0> is_enabled 'bigdata:student'
删除表
注意:首先要将删除的表设置为禁用状态才可以删除,否则会报错
hbase(main):008:0> disable 'bigdata:student'
hbase(main):022:0> drop 'bigdata:student'
新增列族
hbase(main):014:0> alter 'bigdata:student','teacherinfo'
删除列族
hbase(main):016:0> alter 'bigdata:student',{NAME=>'teacherinfo',METHOD=>'delete'}
更改列族存储版本的限制
hbase(main):033:0> alter 'bigdata:student',{NAME=>'baseinfo',VERSIONS=>3}
put 增加数据
put 'bigdata:student','rowkey1','baseinfo:name','tom'
put 'bigdata:student','rowkey1','baseinfo:birthday','1999-01-01'
put 'bigdata:student','rowkey1','baseinfo:age','24'
put 'bigdata:student','rowkey1','schoolinfo:name','aaa'
put 'bigdata:student','rowkey1','schoolinfo:address','jsxueyuan'
put 'bigdata:student','rowkey2','baseinfo:name','jerry'
put 'bigdata:student','rowkey2','baseinfo:birthday','2003-07-02'
put 'bigdata:student','rowkey2','baseinfo:age','20'
put 'bigdata:student','rowkey2','schoolinfo:name','bbb'
put 'bigdata:student','rowkey2','schoolinfo:address','guangzhou'
put 'bigdata:student','rowkey3','baseinfo:name','mands'
put 'bigdata:student','rowkey3','baseinfo:birthday','2022-05-21'
put 'bigdata:student','rowkey3','baseinfo:age','1'
put 'bigdata:student','rowkey3','schoolinfo:name','ccc'
put 'bigdata:student','rowkey3','schoolinfo:address','bj'
put 'bigdata:student','rowkey4','baseinfo:name','roboot'
put 'bigdata:student','rowkey4','baseinfo:birthday','2018-12-31'
put 'bigdata:student','rowkey4','baseinfo:age','5'
put 'bigdata:student','rowkey4','schoolinfo:name','ddd'
put 'bigdata:student','rowkey4','schoolinfo:address','shanghai'
get 查看数据
hbase(main):038:0> get 'bigdata:student','rowkey1'
hbase(main):039:0> get 'bigdata:student','rowkey2'
hbase(main):040:0> get 'bigdata:student','rowkey3'
hbase(main):041:0> get 'bigdata:student','rowkey4'
get条件查询
hbase(main):001:0> get 'bigdata:student','rowkey2','baseinfo'
hbase(main):002:0> get'bigdata:student','rowkey2','schoolinfo'
hbase(main):001:0> get 'bigdata:student','rowkey2','baseinfo:name'
hbase(main):002:0> get 'bigdata:student','rowkey3',{COLUMN=>'baseinfo:name'}
删除指定列族下的指定列
hbase(main):003:0> delete 'bigdata:student','rowkey3','baseinfo:age'
删除指定行
hbase(main):004:0> deleteall 'bigdata:student','rowkey3'
全表扫描
hbase(main):005:0> scan 'bigdata:student'
全表扫描指定列族
hbase(main):006:0> scan 'bigdata:student',COLUMN=>'baseinfo'
全表扫描指定列族指定列
hbase(main):007:0> scan 'bigdata:student',COLUMN=>'baseinfo:birthday'
扫描指定起始行至结束行(不包含)
hbase(main):008:0> scan 'bigdata:student',{COLUMN=>'baseinfo:name',STARTROW=>'rowkey1',STOPROW=>'rowkey4'}
值包含
hbase(main):009:0> scan 'bigdata:student',FILTER=>"ValueFilter(=,'substring:aaa')"
值=
hbase(main):010:0> scan 'bigdata:student',FILTER=>"ValueFilter(=,'binary:24')"
以birth开头的
hbase(main):011:0> scan 'bigdata:student',FILTER=>"ColumnPrefixFilter('birth')"
以birth开头且值中包含2003
hbase(main):014:0> scan 'bigdata:student',FILTER=>"ColumnPrefixFilter('birth') AND ValueFilter(=,'substring:2003')"
以birth开头且值中包含2003 或者1999
hbase(main):018:0> scan 'bigdata:student',FILTER=>"ColumnPrefixFilter('birth') AND (ValueFilter(=,'substring:2003') OR ValueFilter(=,'substring:1999'))"![在这里插入图片描述](https://img-blog.csdnimg.cn/3ee9e7eb297f4f90aaef3835e7f58433.png)