第92课作业,通过SerDes的方式对一下数据进行Hive的存储和查询操作

第92课作业,通过SerDes的方式对一下数据进行Hive的存储和查询操作

第92课作业,通过SerDes的方式对一下数据进行Hive的存储和查询操作:

0^^Hadoop^^America^^5000|8000|12000|level8^^male
1^^Spark^^America^^8000|10000|15000|level9^^famale
2^^Flink^^America^^7000|8000|13000|level10^^male
3^^Hadoop^^America^^9000|11000|12000|level10^^famale
4^^Spark^^America^^10000|11000|12000|level12^^male
5^^Flink^^America^^11000|12000|18000|level18^^famale
6^^Hadoop^^America^^15000|16000|19000|level16^^male
7^^Spark^^America^^18000|19000|20000|level20^^male
8^^Flink^^America^^15000|16000|19000|level19^^male

实现:inputformat格式编码解析,灵活对hive源数据进行清洗

1,按^^进行分割

2,同时也按|进行切分

实现步骤:

1,源数据位置:

root@master:/usr/local/IMF_testdata/hivestudy#ls

employeesinputformat.txt  IMFInputFormat2.jar

2,查看文件内容

root@master:/usr/local/IMF_testdata/hivestudy#cat employeesinputformat.txt

0^^Hadoop^^America^^5000|8000|12000|level8^^male

1^^Spark^^America^^8000|10000|15000|level9^^famale

2^^Flink^^America^^7000|8000|13000|level10^^male

3^^Hadoop^^America^^9000|11000|12000|level10^^famale

4^^Spark^^America^^10000|11000|12000|level12^^male

5^^Flink^^America^^11000|12000|18000|level18^^famale

6^^Hadoop^^America^^15000|16000|19000|level16^^male

7^^Spark^^America^^18000|19000|20000|level20^^male

8^^Flink^^America^^15000|16000|19000|level19^^male

3,开发inputformat代码,源代码附后.导出jar包IMFInputFormat2.jar

代码中使用了正则表达式对文本进行了解析:

String patternhive =  "^(.*)\\^\\^(.*)\\^\\^(.*)\\^\\^(.*)\\|(.*)\\|(.*)\\|(.*)\\^\\^(.*)";

按^^及|进行解析,解析以后进行分组,依次获取各分组的值,然后使用"\u001"组拼接成字符串.

问题:使用"\t"拼接在hive中导入数据为null;

解决:使用"\u001"组拼接成字符串.,顺利导入数据到hive。

4,在hive中的操作:

删表:

drop table employee_inputformat;

导入jar包

add jar/usr/local/IMF_testdata/hivestudy/IMFInputFormat2.jar;

建立表

CREATE TABLEemployee_InputFormat(userid  INT,nameString,address String, salarys1 int ,salarys2 int ,salarys3 int ,salarys4string , gendre string)  stored asINPUTFORMAT 'com.dt.spark.hive.IMFInputFormat' OUTPUTFORMAT'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat';

加载数据

LOAD DATA LOCAL INPATH'/usr/local/IMF_testdata/hivestudy/employeesinputformat.txt' INTO TABLEemployee_InputFormat;

数据查询

select * from employee_InputFormat;

5,运行结果如下:

www.zeeklog.com  - 第92课作业,通过SerDes的方式对一下数据进行Hive的存储和查询操作

hive>    desc formatted employee_inputformat;

OK

# col_name              data_type               comment

userid                  int

name                    string

address                 string

salarys1                int

salarys2                int

salarys3                int

salarys4                string

gendre                  string

# Detailed Table Information

Database:               default

Owner:                  root

CreateTime:             Sun Dec 11 20:47:21 CST 2016

LastAccessTime:         UNKNOWN

Protect Mode:           None

Retention:              0

Location:              hdfs://master:9000/user/hive/warehouse/employee_inputformat

Table Type:             MANAGED_TABLE

Table Parameters:

COLUMN_STATS_ACCURATE   true

numFiles                1

totalSize               467

transient_lastDdlTime  1481460441

# Storage Information

SerDe Library:         org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe

InputFormat:           com.dt.spark.hive.IMFInputFormat

OutputFormat:           org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat

Compressed:             No

Num Buckets:            -1

Bucket Columns:         []

Sort Columns:           []

Storage Desc Params:

serialization.format    1

Time taken: 0.111 seconds, Fetched: 36row(s)

hive>

附件源代码:

package com.dt.spark.hive;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;

import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapred.FileSplit;

import org.apache.hadoop.mapred.InputSplit;

import org.apache.hadoop.mapred.JobConf;

importorg.apache.hadoop.mapred.JobConfigurable;

importorg.apache.hadoop.mapred.RecordReader;

import org.apache.hadoop.mapred.Reporter;

importorg.apache.hadoop.mapred.TextInputFormat;

public class IMFInputFormat extends  TextInputFormat implements

JobConfigurable

{

public RecordReader<LongWritable,Text> getRecordReader(

InputSplit genericSplit, JobConfjob, Reporter reporter)

throws IOException {

reporter.setStatus(genericSplit.toString());

return new IMFRecordReader((FileSplit)genericSplit,job);

}

}

源代码:

package com.dt.spark.hive;

import java.io.IOException;

import java.io.InputStream;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.FSDataInputStream;

import org.apache.hadoop.fs.FileSystem;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.LongWritable;

import org.apache.hadoop.io.Text;

import org.apache.hadoop.io.compress.CompressionCodec;

import org.apache.hadoop.io.compress.CompressionCodecFactory;

import org.apache.hadoop.mapred.FileSplit;

import org.apache.hadoop.util.LineReader;

import org.apache.hadoop.mapred.RecordReader;

public  class IMFRecordReader implements RecordReader<LongWritable,Text> {

private CompressionCodecFactorycompressionCodecs = null;

private  long start;

private  long pos;

private  long end;

private LineReaderlineReader;

int  maxLineLength;

public IMFRecordReader(FileSplitinputSplit, Configuration job) throws IOException {

maxLineLength =  job.getInt("mapred.IMFRecordReader.maxlength", Integer.MAX_VALUE);

start =  inputSplit.getStart();

end =  start + inputSplit.getLength();

final Pathfile = inputSplit.getPath();

compressionCodecs = new CompressionCodecFactory(job);

final CompressionCodeccodec = compressionCodecs.getCodec(file);

// Open file and seek to thestart of the split

FileSystem fs =  file.getFileSystem(job);

FSDataInputStream fileIn =fs.open(file);

booleanskipFirstLine = false;

if (codec !=null) {

lineReader = new LineReader(codec.createInputStream(fileIn),job);

end = Long.MAX_VALUE;

} else {

if (start != 0) {

skipFirstLine = true;

--start;

fileIn.seek(start);

}

lineReader = new LineReader(fileIn,job);

}

if (skipFirstLine) {

start +=  lineReader.readLine(new Text(), 0, (int) Math.min((long) Integer.MAX_VALUE,end - start));

}

this.pos =start;

}

public IMFRecordReader(InputStreamin, longoffset, longendOffset, intmaxLineLength) {

this.maxLineLength =maxLineLength;

this.lineReader =new LineReader(in);

this.start =offset;

this.pos =offset;

this.end =endOffset;

}

public IMFRecordReader(InputStreamin, longoffset, longendOffset, Configuration job) throws IOException {

this.maxLineLength =job.getInt("mapred.IMFRecordReader.maxlength", Integer.MAX_VALUE);

this.lineReader =new LineReader(in,job);

this.start =offset;

this.pos =offset;

this.end =endOffset;

}

public LongWritable createKey() {

return  new LongWritable();

}

public Text createValue() {

return  new Text();

}

/**

* Reads the next record inthe split. getusefull fields from the raw nginx

* log.

*

* @param key

*            key of the record which will map tothe byte offset of the

*            record's line

* @param value

*            the record in text format

* @return true if a recordexisted, false otherwise

* @throws IOException

*/

public  synchronized boolean next(LongWritablekey, Text value)throws IOException {

// Stay within the split

while (pos <end) {

key.set(pos);

intnewSize = lineReader.readLine(value, maxLineLength,

Math.max((int) Math.min(Integer.MAX_VALUE,end - pos),maxLineLength));

if (newSize == 0)

return  false;

String patternhive ="^(.*)\\^\\^(.*)\\^\\^(.*)\\^\\^(.*)\\|(.*)\\|(.*)\\|(.*)\\^\\^(.*)";

Pattern phive = Pattern.compile(patternhive);

String strhive =  value.toString();

Matcher mhive =  phive.matcher(strhive);

String resultstr =  "defaultisblank";

while (mhive.find()) {

resultstr =  mhive.group(1) + "\001" +  mhive.group(2) + "\001" +  mhive.group(3) + "\001" +  mhive.group(4)

+ "\001" +mhive.group(5) + "\001" +mhive.group(6) + "\001" +"IMF" + mhive.group(7) +"\001"

+ mhive.group(8);

}

;

if (resultstr ==null || resultstr == "defaultisblank") {

} else {

value.set(resultstr);

pos +=  newSize;

if (newSize <maxLineLength)

returntrue;

}

}

return  false;

}

public  float getProgress() {

if (start ==end) {

return 0.0f;

} else {

return Math.min(1.0f, (pos -start) / (float) (end -start));

}

}

public  synchronized long getPos() throws IOException {

returnpos;

}

public  synchronized void close() throws IOException {

if (lineReader !=null)

lineReader.close();

}

}

www.zeeklog.com  - 第92课作业,通过SerDes的方式对一下数据进行Hive的存储和查询操作


www.zeeklog.com  - 第92课作业,通过SerDes的方式对一下数据进行Hive的存储和查询操作

Read more

springboot在线教学平台

springboot在线教学平台

基于springboot+vue实现的在线教学平台  (源码+L文+ppt)4-069 4.1系统结构设计 这些功能可以充分满足在线教学平台的需求。此系统功能较为全面如下图系统功能结构如图4-1所示。 图4-1功能结构图 4.2系统功能模块设计 在线教学平台的使用者主要有二类用户,一类是管理员,他拥有整个系统的最高权限,然后是学员,他具有管理员给予级别的权限,都只能对自己的个人信息进行操作。系统根据这二类用户,划分出了二大功能模块。 4.3 数据库设计 4.3.1 概念模型设计 概念模型是对现实中的问题出现的事物的进行描述,ER图是由实体线以及关联构成的图,E-R图可以明确地叙述系统中涵盖的实体线相互关系。 在线测试E-R图如图4-2所示: 图4-2在线测试E-R图 考试记录E-R图如图4-3所示: 图4-3考试记录E-R图 试题信息E-R图如图4-4所示: 图4-4试题信息E-R图 学员信息E-R图如图4-5所示: 图4-5学员信息E-R图 学习资料E-R图如图4-6所示: 图4-6学习资料E-R图 在线教学平台总体E-R图如图4-7所示:

By Ne0inhk
基于Java的学生档案管理系统

基于Java的学生档案管理系统

基于springboot+vue实现的学生档案管理系统  (源码+L文+ppt)4-065 第4章 系统设计 4.1 总体功能设计 学生档案管理系统的总体功能设计包括学生信息管理、课程管理、教师信息管理、成绩管理和系统配置管理。系统将提供用户友好的界面,支持学生信息的录入、查询和更新,包括个人信息、学籍信息、就业信息等。系统将支持课程信息的管理,包括课程的录入、查询和排课安排。教师信息管理功能将允许管理员管理教师的个人信息和所教授课程信息。成绩管理模块将支持成绩录入、查询和统计分析功能,以便于学校管理人员和教师监控学生成绩情况。系统配置管理功能将提供对系统参数和配置文件的管理,以确保系统能够按照学校的需求进行定制和设置。 整体系统的主要功能模块如图4-1: 图4-1 学生档案管理系统功能图 4.2 系统登录模块设计 用户在启动操作系统时会调用的一个模块。该模型通过用户输入的账号、密码来确定应用的类别,切换到该类应用的页面。 本模块的功能点包括: 1)确定账号与密码是否一致。 2)完全按照系统所规定使用权限的权限类型,,直接通过登陆进入到系统权限的制定管理页面中即可进

By Ne0inhk
个人健康档案管理系统

个人健康档案管理系统

基于springboot+vue实现的个人健康档案管理系统(源码+L文+ppt)4-076 4.1 系统功能结构设计 根据对个人健康档案管理系统的具体需求分析,把系统可以划分为几个不同的功能模块:管理员可以对系统首页、用户管理、健康体检管理、疫苗提醒管理、用药信息管理、疾病诊断管理、饮食记录管理、运动记录管理、睡眠质量管理、健康报告管理、系统管理、我的信息等功能进行操作,个人健康档案管理系统各功能划分结构如图4-1所示。 4.2 数据库设计 4.2.1数据库概念结构设计 一个网站的成功上线运营,离不开强大的数据库支持。一个设计良好的数据库是支撑拥有多种功能网站的关键所在。我在设计网站的时候采用的是MySQL数据库,其与Java、Apache服务器的完美结合,构造成了WEB中的铁三角。 数据根据教师指导与调查分析,信息世界的基本要素包括实体和关联。现实存在且彼此可区别的事物称为实体。实体可以是实际的人、事或物,还可以是抽象化的概念或联络。在系统中将“用户、健康体检、疫苗提醒、用药信息、疾病诊断、饮食记录”

By Ne0inhk
springbootOA管理系统

springbootOA管理系统

基于springboot+vue实现的OA管理系统  (源码+L文+ppt)4-069 第四章 系统设计 4.1 系统总体结构设计 本系统是基于B/S架构的网站系统,全方面的对系统的资讯进行实时的更新,对系统进行实时的维护。它的主要功能包括员工管理、部门管理、工资发放管理、客户信息管理、日程安排管理、车辆信息管理、文件信息管理、工资日志管理、签到信息管理、通知公告管理、我的信息等。系统总体结构图如下所示: 图4-1 系统总体结构图 4.2 数据库设计 数据库的设计对于准确反映系统需求至关重要。它直接关系到整个系统最终的呈现结果。通过之前的分析梳理,我们已经明确了系统中需要包含的功能和要求。除了对数据库进行增加、删除、查询和修改等基础操作外,还需要理清实体间的对应关系。基于这些考虑,我们完成了表结构的设计与实现。 4.2.1 数据库逻辑设计 为了更直观阐明数据库的设计,使用 Vision 绘制的OA管理系统数据模型E-R实体属性图。

By Ne0inhk