02 HBase Shell综合示例
创建表,插入数据
create 'users','user_id','address','info'
put 'users','xiaoming','info:age','24'
put 'users','xiaoming','info:birthday','1987-06-17'
put 'users','xiaoming','info:company','alibaba'
put 'users','xiaoming','address:country','China'
put 'users','xiaoming','address:province','zhejiang'
put 'users','xiaoming','address:city','hangzhou'
put 'users','zhangyifei','info:birthday','1987-4-17'
put 'users','zhangyifei','info:favorite','movie'
put 'users','zhangyifei','address:country','China'
put 'users','zhangyifei','address:province','guangdong'
put 'users','zhangyifei','address:city','jieyang'
put 'users','zhangyifei','address:town','xianqiao'
基本业务操作
# 获取一个id的所有数据
get 'users','xiaoming'
# 获取一个id、一个列族的所有数据
get 'users','xiaoming','info'
# 获取一个id、一个列族中一个列的所有数据
get 'users','xiaoming','info:age'
# 更新操作
alter 'users',{NAME=>'info',VERSIONS=>3}
put 'users','xiaoming','info:age','29'
get 'users','xiaoming','info:age'
put 'users','xiaoming','info:age','30'
get 'users','xiaoming','info:age'
# 获取单元格中不同版本数据
# 第一种:利用版本号(每次数据更新,版本号会自动执行+1操作)
get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>3}
# 第二种,使用插入数据时的时间戳
get 'users','xiaoming',{COLUMN=>'info:age',TIMESTAMP=>1610606994411}
# 删除操作
# 删除xiaoming值的info:age字段(会删除之前操作的数据,直到完全删除字段)
delete 'users','xiaoming','info:age'
get 'users','xiaoming'
# 统计表的行数
count 'users'
# 删除整行
delete 'users','xiaoming'
count 'users'
# 清空表
truncate 'users'