02 HBase Shell综合示例

创建表,插入数据

  1. create 'users','user_id','address','info'
  2. put 'users','xiaoming','info:age','24'
  3. put 'users','xiaoming','info:birthday','1987-06-17'
  4. put 'users','xiaoming','info:company','alibaba'
  5. put 'users','xiaoming','address:country','China'
  6. put 'users','xiaoming','address:province','zhejiang'
  7. put 'users','xiaoming','address:city','hangzhou'
  8. put 'users','zhangyifei','info:birthday','1987-4-17'
  9. put 'users','zhangyifei','info:favorite','movie'
  10. put 'users','zhangyifei','address:country','China'
  11. put 'users','zhangyifei','address:province','guangdong'
  12. put 'users','zhangyifei','address:city','jieyang'
  13. put 'users','zhangyifei','address:town','xianqiao'

基本业务操作

  1. # 获取一个id的所有数据
  2. get 'users','xiaoming'
  3. # 获取一个id、一个列族的所有数据
  4. get 'users','xiaoming','info'
  5. # 获取一个id、一个列族中一个列的所有数据
  6. get 'users','xiaoming','info:age'
  7. # 更新操作
  8. alter 'users',{NAME=>'info',VERSIONS=>3}
  9. put 'users','xiaoming','info:age','29'
  10. get 'users','xiaoming','info:age'
  11. put 'users','xiaoming','info:age','30'
  12. get 'users','xiaoming','info:age'
  13. # 获取单元格中不同版本数据
  14. # 第一种:利用版本号(每次数据更新,版本号会自动执行+1操作)
  15. get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>3}
  16. # 第二种,使用插入数据时的时间戳
  17. get 'users','xiaoming',{COLUMN=>'info:age',TIMESTAMP=>1610606994411}
  18. # 删除操作
  19. # 删除xiaoming值的info:age字段(会删除之前操作的数据,直到完全删除字段)
  20. delete 'users','xiaoming','info:age'
  21. get 'users','xiaoming'
  22. # 统计表的行数
  23. count 'users'
  24. # 删除整行
  25. delete 'users','xiaoming'
  26. count 'users'
  27. # 清空表
  28. truncate 'users'