大数据技术Hbase列数据库——topic2

实验十三

练习一

1.创建一个命名空间并查看

create_namespace 'bigdata'
list_namespace

2.在该命名空间中创建一个学生表(包含两个列簇),并查看该表的详细信息

create 'bigdata:student','info1','info2'
desc 'bigdata:student'

3.为学生表再增加一个列簇,VERSIONS为3

alter 'bigdata:student',{NAME=>'info3',VERSION=>3}

4.在默认的命名空间下创建一个动物表(包含两个列簇,这两个列簇的VERSION为5)

create 'animal',{NAME=>'info1',VERSION=>5}{NAME=>'info2',VERSION=>5}

5.在Web界面查看自己创建的两张表的信息

192.168.13.6:16010

在执行前需要先关闭防火墙,否则会失败
6.删除动物表中的任一列簇

alter 'animal',{NAME=>'info2',METHOD=>'delete'}
或
alter 'animal''delete'=>'info2'

HBase 表至少要包含一个列族,因此当表中只有一个列族时,无法将其删除。

练习二

1.使用hbase shell创建员工表,包含员工基本信息(员工姓名,年龄,家庭地址,身份证号)和公司信息(公司名称,入职时间,薪水)两个列簇

create 'employee','base_Info','firm_Info'

2.为员工表添加4行数据

put 'employee', 'row1', 'base_info:name', 'Alice'  
put 'employee', 'row1', 'base_info:age', '30'  
put 'employee', 'row1', 'base_info:address', 'HN'  
put 'employee', 'row1', 'base_info:id', '4123' 
put 'employee', 'row1', 'firm_info:name', 'HUAWEI'  
put 'employee', 'row1', 'firm_info:time', '2018-03-08'  
put 'employee', 'row1', 'firm_info:wage', '15000'  

put 'employee', 'row2', 'base_info:name', 'nini'  
put 'employee', 'row2', 'base_info:age', '20'  
put 'employee', 'row2', 'base_info:address', 'ZD'  
put 'employee', 'row2', 'base_info:id', '4113' 
put 'employee', 'row2', 'firm_info:name', 'XIAOMI'  
put 'employee', 'row2', 'firm_info:time', '2020-05-06'  
put 'employee', 'row2', 'firm_info:wage', '12000'  

put 'employee', 'row3', 'base_info:name', 'chaochao'  
put 'employee', 'row3', 'base_info:age', '22'  
put 'employee', 'row3', 'base_info:address', 'BJ'  
put 'employee', 'row3', 'base_info:id', '4321' 
put 'employee', 'row3', 'firm_info:name', 'CCTV'  
put 'employee', 'row3', 'firm_info:time', '2021-10-08'  
put 'employee', 'row3', 'firm_info:wage', '9000' 

put 'employee', 'row4', 'base_info:name', 'Ken'  
put 'employee', 'row4', 'base_info:age', '25'  
put 'employee', 'row4', 'base_info:address', 'HB'  
put 'employee', 'row4', 'base_info:id', '4567' 
put 'employee', 'row4', 'firm_info:name', 'DELL'  
put 'employee', 'row4', 'firm_info:time', '2019-06-10'  
put 'employee', 'row4', 'firm_info:wage', '8000' 

3.利用scan查询整个表中的数据

scan 'employee'

4.获取任意一行的信息

get 'employee','row1'

5.获取任意一个列簇的信息

scan 'employee',{COLUMN=>'firm_info'}

6.获取任意一列的信息

scan 'employee',{COLUMN=>'firm_info:name'}

7.查询第2-3行的数据

scan 'employee', {STARTROW => 'row2',STOPROW => 
'row4'}

练习三

1.请创建一个student表,其中包含address和score两个列簇,具体结构如下所示:
在这里插入图片描述

请使用HBase Shell完成以下需求:
1、创建表student有两个列族address和score。

create 'student','address','score'

2、向student表中添加上表中的数据。

put 'student', 'zhangsan', 'address:province', 'henan'  
put 'student', 'zhangsan', 'address:city', 'zhengzhou'  
put 'student', 'zhangsan', 'address:street', 'dongqing'  
put 'student', 'zhangsan', 'score:java', '80'  
put 'student', 'zhangsan', 'score:hadoop', '83'  
put 'student', 'zhangsan', 'score:math', '85'  

put 'student', 'lisi', 'address:province', 'beijing'  
put 'student', 'lisi', 'address:city', 'beijng'  
put 'student', 'lisi', 'address:street', 'changan'  
put 'student', 'lisi', 'score:java', '81' 
put 'student', 'lisi', 'score:hadoop', '84'  
put 'student', 'lisi', 'score:math', '89' 

scan 'student' 

3、查询“zhangsan”的地址(address)。

scan 'Student', 'zhangsan', {COLUMN => 'address'}  
get 'student', 'zhangsan','address'  

4、查询“lisi”的“hadoop”成绩 。

scan 'Student', 'lisi', {COLUMN => 'score:hadoop'}  
get 'Student','lisi','score:hadoop'

5、查询student表中score列簇的数据。

scan 'student', {COLUMN => 'score:'}  

6、查询值等于 80的所有数据。

scan 'student', {FILTER => "ValueFilter(=, 'binary:80')"}  

7、查询值包含 beijing 的所有数据。

scan 'student', {FILTER => "ValueFilter(=, 'substring:beijing')"}  

8、查询列名中的前缀为pro 的数据。

scan 'student', {FILTER => "ColumnPrefixFilter('pro')"} 

9、查询rowkey前缀为li的数据。

scan 'student', {FILTER => "RowFilter(=, 'prefixfilter:li')"}  

10、查询列名前缀为ci并且列值中包含zheng的数据。

scan 'student', {FILTER => "ColumnPrefixFilter('ci') AND ValueFilter(=, 'substring:zheng')"

相关推荐

  1. 数据技术Hbase数据库——topic2

    2024-06-07 15:44:01       7 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-07 15:44:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-07 15:44:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-07 15:44:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-07 15:44:01       20 阅读

热门阅读

  1. 酒茶元宇宙 - 探索味觉与科技的融合奇迹

    2024-06-07 15:44:01       10 阅读
  2. DALL-E 2之学习心得

    2024-06-07 15:44:01       8 阅读