当前位置:   article > 正文

在HBase中创建‘sutdent’表练习_hbase创建表的作业

hbase创建表的作业

首先

启动hadoop:start-all.sh

启动hbase:start-hbase.sh

启动hbase shell客户端,进入创表:

1.在HBase中创建‘sutdent’表,如图所示:

<1>创建命名空间,建立一个test的命名空间,通过如下describe命令来查看所建立的命名空间的详细信息,具体的命令如下:

  1. #1、创建命名空间
  2. hbase(main):006:0> create_namespace 'test' 
  3. Took 0.8661 seconds
  1. #2、查看所建立的命名空间的详细信息
  2.  hbase(main):009:0> describe_namespace 'test'
  3. DESCRIPTION                                                          
  4. {NAME => 'test'}                                                      
  5. Quota is disabled
  6. Took 1.1768 seconds

<2>建立一个student表,有5个列族,有name,age,sex,id,score。具体的命令如下:

  1. #1、查看当前数据库中有哪些表
  2. hbase(main):010:0> list
  3. TABLE                                                                
  4. 0 row(s)
  5. Took 0.0386 seconds                                                  
  6. => []
  7. #2、创建表student5
  8. hbase(main):023:0> create 'student5','info1','info2'
  9. Created table student5
  10. Took 2.5662 seconds                                                                   
  11. => Hbase::Table - student5
  12. #3、其数据内容如下:
  13. hbase(main):025:0> put 'student5','rk01','info1:name','zhangsan'
  14. Took 0.5119 seconds                                                                   
  15. hbase(main):026:0> put 'student5','rk01','info1:age','18'
  16. Took 0.0185 seconds                                                                   
  17. hbase(main):027:0> put 'student5','rk01','info1:sex','man'
  18. Took 0.0166 seconds 
  19. hbase(main):030:0> put 'student5','rk01','info2:id','11111'
  20. Took 0.0918 seconds                                                                   
  21. hbase(main):031:0> put 'student5','rk01','info2:score','90'
  22. Took 0.0137 seconds
  23. #4、查看表信息:
  24. hbase(main):033:0>  scan 'student5'
  25. ROW                    COLUMN+CELL                                                    
  26.  rk01                  column=info1:age, timestamp=1681358763438, value=18            
  27.  rk01                  column=info1:name, timestamp=1681358735922, value=zhangsan     
  28.  rk01                  column=info1:sex, timestamp=1681358779985, value=man            
  29.  rk01                  column=info2:id, timestamp=1681359019121, value=11111          
  30.  rk01                  column=info2:score, timestamp=1681359031401, value=90          
  31. 1 row(s)
  32. Took 0.3260 seconds  

2.向表中插入至少两条数据(zhangsan,18,man,11111,90)

  1. #插入第一条数据
  2. hbase(main):025:0> put 'student5','rk01','info1:name','zhangsan'
  3. Took 0.5119 seconds                                                                   
  4. hbase(main):026:0> put 'student5','rk01','info1:age','18'
  5. Took 0.0185 seconds                                                                    
  6. hbase(main):027:0> put 'student5','rk01','info1:sex','man'
  7. Took 0.0166 seconds 
  8. hbase(main):030:0> put 'student5','rk01','info2:id','11111'
  9. Took 0.0918 seconds                                                                    
  10. hbase(main):031:0> put 'student5','rk01','info2:score','90'
  11. Took 0.0137 seconds
  12. #插入第二条数据
  13. hbase(main):020:0> put 'student5','rk02','info1:name','zhhuan'
  14. Took 0.4455 seconds                                                                                        
  15. hbase(main):021:0>  put 'student5','rk02','info1:age','22'
  16. Took 0.0158 seconds                                                                                       
  17. hbase(main):022:0> put 'student5','rk02','info1:sex','woman'
  18. Took 0.0163 seconds                                                                                       
  19. hbase(main):023:0> put 'student5','rk02','info2:id','11112'
  20. Took 0.0212 seconds                                                                                       
  21. hbase(main):024:0> put 'student5','rk02','info2:score','90'
  22. Took 0.0378 seconds 
  23. #插入第三条数据:
  24. hbase(main):028:0> put 'student5','rk03','info1:name','zhjie'
  25. Took 0.1387 seconds                                                                                       
  26. hbase(main):029:0>  put 'student5','rk03','info1:age','30'
  27. Took 0.0198 seconds                                                                                       
  28.                                                                                     
  29. hbase(main):031:0> put 'student5','rk03','info2:id','11113'
  30. Took 0.0223 seconds                                                                                       
  31. hbase(main):032:0> put 'student5','rk03','info1:sex','man'
  32. Took 0.0303 seconds                                                                                        
  33.                                                                                       
  34. hbase(main):034:0> put 'student5','rk03','info2:score','93'
  35. Took 0.0146 seconds

 

3.修改名字为zhangsan的性别为woman

  1. #修改
  2. hbase(main):046:0> put 'student5','rk01','info1:sex','woman'
  3. Took 0.0497 seconds  
  4. #查询修改结果

4.查询性别为女的所有的人名

  1. hbase(main):003:0> scan 'student5',{FILTER=>"SingleColumnValueFilter('info1':'sex',=,'binary:woman')  AND QualifierFilter(=,'binary:name')  ",FORMATTER => 'toString'}
  2. ROW                      COLUMN+CELL                                                         
  3.  rk01                    column=info1:name, timestamp=1682042269553, value=zhangsan          
  4.  rk02                    column=info1:name, timestamp=1682041446301, value=zhhuan            
  5. 2 row(s)
  6. Took 0.6609 seconds   

5.删除名字为张三的数据

  1. #删除数据
  2. hbase(main):017:0> deleteall 'student5','zhangsan'
  3. Took 0.1570 seconds 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/502432
推荐阅读
相关标签
  

闽ICP备14008679号