2024.11.12

实验3

熟悉常用的HBase操作

 

 

1.实验目的

1理解HBaseHadoop体系结构中的角色;

2熟练使用HBase操作常用的Shell命令;

3熟悉HBase操作常用的Java API

2.实验平台

1操作系统:Linux(建议Ubuntu16.04Ubuntu18.04);

2Hadoop版本:3.1.3

3HBase版本:2.2.2

4JDK版本:1.8

5Java IDEEclipse

3. 实验步骤

(一)编程实现以下指定功能,并用Hadoop提供的HBase Shell命令完成相同任务:

列出HBase所有的表的相关信息,例如表名;

表为空

 

首先创建一个表,就按照下面的学生表创建。create 'Student','Sname','Ssex','Sage','Sdept'

 

在插入一些信息。

put 'Student', 'row1', 'Sname', '王瑞'

put 'Student', 'row1', 'Ssex', ''

put 'Student', 'row1', 'Sage', '100'

put 'Student', 'row1', 'Sdept', 'Computer'

 

put 'Student', 'row2', 'Sname', '小明'

put 'Student', 'row2', 'Ssex', ''

put 'Student', 'row2', 'Sage', '22'

put 'Student', 'row2', 'Sdept', 'dirt'

 

put 'Student', 'row3', 'Sname', '小李'

put 'Student', 'row3', 'Ssex', ''

put 'Student', 'row3', 'Sage', '20'

put 'Student', 'row3', 'Sdept', 'physics'

查看表名。

 

在终端打印出指定的表的所有记录数据;

我插入的中文数据他没法识别,只能是显示字符,但是可以查看记录。

 

修改一下数据。

 

向已经创建好的表添加和删除指定的列族或列;

添加名为 'NewC' 的列

 

删除列 'Sname'  

 

 

清空指定的表的所有记录数据;

truncate 'Student'清除

 

统计表的行数。

count 'Student'

 

(二)HBase数据库操作

1. 现有以下关系型数据库中的表和数据(见表14-3到表14-5,要求将其转换为适合于HBase存储的表并插入数据:

14-3 学生表(Student

学号(S_No

姓名(S_Name

性别(S_Sex

年龄(S_Age

2015001

Zhangsan

male

23

2015002

Mary

female

22

2015003

Lisi

male

24

 

14-4 课程表(Course

课程号(C_No

课程名(C_Name

学分(C_Credit

123001

Math

2.0

123002

Computer Science

5.0

                                 123003

English

3.0

 

14-5 选课表(SC

学号(SC_Sno

课程号(SC_Cno

成绩(SC_Score

2015001

123001

86

2015001

123003

69

2015002

123002

77

2015002

123003

99

2015003

123001

98

2015003

123002

95

首先创建三个表。

create 'Student', 'info'  

create 'Course', 'info'  

create 'SC', 'info'

 

posted @ 2024-11-12 09:18  kuku睡  阅读(8)  评论(0)    收藏  举报