1.数据的预处理阶段
2.数据的入库操作阶段
3.数据的分析阶段
4.数据保存到数据库阶段
5.数据的查询显示阶段  使用 HBaseAPi查询 (这里就不写了 重要的是上面的离线流程)

原始数据:

qR8WRLrO2aQ:mienge:406:People & Blogs:599:2788:5:1:0:4UUEKhr6vfA:zvDPXgPiiWI:TxP1eXHJQ2Q:k5Kb1K0zVxU:hLP_mJIMNFg:tzNRSSTGF4o:BrUGfqJANn8:OVIc-mNxqHc:gdxtKvNiYXc:bHZRZ-1A-qk:GUJdU6uHyzU:eyZOjktUb5M:Dv15_9gnM2A:lMQydgG1N2k:U0gZppW_-2Y:dUVU6xpMc6Y:ApA6VEYI8zQ:a3_boc9Z_Pc:N1z4tYob0hM:2UJkU2neoBs

预处理之后的数据:

qR8WRLrO2aQ:mienge:406:People,Blogs:599:2788:5:1:0:4UUEKhr6vfA,zvDPXgPiiWI,TxP1eXHJQ2Q,k5Kb1K0zVxU,hLP_mJIMNFg,tzNRSSTGF4o,BrUGfqJANn8,OVIc-mNxqHc,gdxtKvNiYXc,bHZRZ-1A-qk,GUJdU6uHyzU,eyZOjktUb5M,Dv15_9gnM2A,lMQydgG1N2k,U0gZppW_-2Y,dUVU6xpMc6Y,ApA6VEYI8zQ,a3_boc9Z_Pc,N1z4tYob0hM,2UJkU2neoBs

  1. 对原始数据进行预处理,格式为上面给出的预处理之后的示例数据。

  2. 通过观察原始数据形式,可以发现,每个字段之间使用“:”分割,视频可以有多个视频类别,类别之间&符号分割,且分割的两边有空格字符,同时相关视频也是可以有多个,多个相关视频也是用“:”进行分割。为了分析数据时方便,我们首先进行数据重组清洗操作。

    即:将每条数据的类别用“,”分割,同时去掉两边空格,多个“相关视频id”也使用“,”进行分割

  1. 数据的预处理阶段 :

实现效果【截图】 

实现代码【代码与截图】:

package MapReduce;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import java.io.IOException;/*** Created by 一个蔡狗 on 2020/1/2.*/
public class DPMap {public static void main(String[] args) throws Exception {Configuration conf = new Configuration();Job job = new Job(conf, "DPjob");job.setJarByClass(DPMap.class);job.setInputFormatClass(TextInputFormat.class);TextInputFormat.addInputPath(job, new Path("E:\\video.txt"));job.setMapperClass(DPmap.class);job.setMapOutputKeyClass(LongWritable.class);job.setMapOutputValueClass(Text.class);job.setReducerClass(DPReduce.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(LongWritable.class);job.setOutputFormatClass(TextOutputFormat.class);TextOutputFormat.setOutputPath(job, new Path("E:\\video2"));System.exit(job.waitForCompletion(true) ? 0 : 1);}static class DPmap extends Mapper<LongWritable, Text, LongWritable, Text> {@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {String[] split = value.toString().split(":");if (split.length > 10) {String Categoryold = split[3];String Categorynew = "";String Relatedidsold = "";String Relateidsnew = "";Relatedidsold = split[9];if (split.length == 10) {//处理 视频类别Categorynew = Util.replacedata(Categoryold);//数据相关视频 IDRelateidsnew = Relatedidsold;} else if (split.length > 10) {//处理视频类别Categorynew = Util.replacedata(Categoryold);//数据相关视频 IDRelatedidsold = value.toString().substring(value.toString().indexOf(split[9]));Relateidsnew = "";}for (int i = 9; i < split.length; i++) {Relateidsnew += split[i] + ",";}Relateidsnew.substring(0, Relateidsnew.lastIndexOf(","));String datas = "";datas = value.toString().replace(Categoryold, Categorynew);String data2 = "";data2 = datas.replace(Relatedidsold, Relateidsnew);context.write(new LongWritable(111), new Text(data2));}}}static class DPReduce extends Reducer<LongWritable, Text, Text, LongWritable> {@Overrideprotected void reduce(LongWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {//遍历value  进行 输出for (Text value : values) {context.write(value, null);}}}}

Map代码截图:

Map代码 :

 static class DPmap extends Mapper<LongWritable, Text, LongWritable, Text> {@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {String[] split = value.toString().split(":");if (split.length > 10) {String Categoryold = split[3];String Categorynew = "";String Relatedidsold = "";String Relateidsnew = "";Relatedidsold = split[9];if (split.length == 10) {//处理 视频类别Categorynew = Util.replacedata(Categoryold);//数据相关视频 IDRelateidsnew = Relatedidsold;} else if (split.length > 10) {//处理视频类别Categorynew = Util.replacedata(Categoryold);//数据相关视频 IDRelatedidsold = value.toString().substring(value.toString().indexOf(split[9]));Relateidsnew = "";}for (int i = 9; i < split.length; i++) {Relateidsnew += split[i] + ",";}Relateidsnew.substring(0, Relateidsnew.lastIndexOf(","));String datas = "";datas = value.toString().replace(Categoryold, Categorynew);String data2 = "";data2 = datas.replace(Relatedidsold, Relateidsnew);context.write(new LongWritable(111), new Text(data2));}}}

Reduce代码截图:

Reduce代码:

 static class DPReduce extends Reducer<LongWritable, Text, Text, LongWritable> {@Overrideprotected void reduce(LongWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException {//遍历value  进行 输出for (Text value : values) {context.write(value, null);}}}

Util代码:

package MapReduce;/*** Created by 一个蔡狗 on 2020/1/2.*/
public class Util {public  static  String replacedata   (String Category){String  Categorys="";if (Category.contains("&")){String[] Categorylist = Category.split("&");for (String OneCategory : Categorylist) {String trim = OneCategory.trim();Categorys+=trim+",";}return  Category.substring(0,Categorys.lastIndexOf(","));}return  Category;}}

驱动代码:

   public static void main(String[] args) throws Exception {Configuration conf = new Configuration();Job job = new Job(conf, "MyMapperReduceDriver");job.setJarByClass(MyMApperReduce.class);job.setInputFormatClass(TextInputFormat.class);TextInputFormat.addInputPath(job, new Path("E:\\video.txt"));job.setMapperClass(MyMapper.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(Text.class);job.setReducerClass(MyReduce.class);job.setOutputKeyClass(NullWritable.class);job.setOutputValueClass(Text.class);job.setOutputFormatClass(TextOutputFormat.class);TextOutputFormat.setOutputPath(job, new Path("E:\\video2"));System.exit(job.waitForCompletion(true) ? 0 : 1);}

把预处理之后的数据进行入库到   hive    中 

     创建数据库和表 

数据入库效果【截图】:

 数据入库命令【命令】

创建数据库名字为:video

创建原始数据表:

视频表:video_ori  用户表:video_user_ori

创建ORC格式的表:

视频表:video_orc 用户表:video_user_orc

给出创建原始表语句

创建video_ori视频表:

create table video_ori(

videoId string,

uploader string,

age int,

category array<string>,

length int,

views int,

rate float,

ratings int,

comments int,

relatedId array<string>)

row format delimited

fields terminated by ":"

collection items terminated by ","

stored as textfile;

创建video_user_ori用户表:

create table video_user_ori(

uploader string,

videos int,

friends int)

row format delimited

fields terminated by ","

stored as textfile;

请写出ORC格式的建表语句:

create table video_orc(videoId string,uploader string,age string,category string,length string,views string,rate string,ratings string,comments string,relatedId string)row format delimitedfields terminated by ":"stored as ORC;create table video_user_orc(uploader string,videos string,friends string)row format delimitedfields terminated by ","stored as ORC;

分别导入预处理之后的视频数据到原始表video_ori和导入原始用户表的数据到video_user_ori

video_ori:

load data local inpath '/opt/part-r-00000' ovewrite  into table video_ori;

video_user_ori:

load data local inpath '/opt/user.txt' into table video_user_ori;

从原始表查询数据并插入对应的ORC表

video_orc:

insert into table video_orc select * from video_ori;

video_user_orc:

insert into table video_user_orc select * from video_user_ori;

对入库之后的数据进行  hivesql  查询操作

从视频表中统计出视频评分为5分的视频信息,把查询结果保存到/export/rate.txt

#! bin/bashhive -e "select * from video.video_orc where rate=5 " > /export/rate.txt

从视频表中统计出评论数大于100条的视频信息,把查询结果保存到/export/comments.txt

#! bin/bash
hive -e "select * from video.video_orc where comments >100 " >/export/comments.txt

创建hive对应的数据库外部表

创建rate外部表的语句:

create external  table rate(

videoId string,

uploader string,

age string,

category string,

length string,

views string,

rate string,

ratings string,

comments string,

relatedId string)

row format delimited

fields terminated by "\t"

stored as textfile;

创建comments外部表的语句:

   create external  table comments(

    videoId string,

    uploader string,

    age string,

    category string,

    length string,

    views string,

    rate string,

    ratings string,

    comments string,

    relatedId string)

row format delimited

fields terminated by "\t"

stored as textfile;

加载第3步的结果数据到外部表中

数据加载语句

load data local inpath '/opt/5.txt' into table rate;

load data local inpath '/opt/100.txt' into table comments;

创建hive  hbase映射表

Hive中的rate,comments两个表分别对应hbase中的hbase_rate,hbase_comments两个表

create table video.hbase_rate(

  videoId string,

    uploader string,

    age string,

    category string,

    length string,

    views string,

    rate string,

    ratings string,

    comments string,

    relatedId string)  

stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'  

with serdeproperties("hbase.columns.mapping" = "cf:uploader,cf:age,cf:category,cf:length,cf:views,cf:rate,cf:ratings,cf:comments,cf:relatedId")

tblproperties("hbase.table.name" = "hbase_rate");

create table video.hbase_comments(

  videoId string,

    uploader string,

    age string,

    category string,

    length string,

    views string,

    rate string,

    ratings string,

    comments string,

    relatedId string)

stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'  

with serdeproperties("hbase.columns.mapping" = "cf:uploader,cf:age,cf:category,cf:length,cf:views,cf:rate,cf:ratings,cf:comments,cf:relatedId")

tblproperties("hbase.table.name" = "hbase_comments");

请写出通过insert overwrite select插入hbase_rate表的语句

insert into table hbase_rate select * from rate;

insert into table hbase_comments select * from comments;

大数据离线流程(小练习二)相关推荐

  1. 大数据离线流程(小练习)

    原始数据: LZi2ryWsShY!lovejoy71!433!People & Blogs!111!47234!4.94!65!32!9G3rVGW4JrI!UnfbKKvUG9Q!753j ...

  2. 迁移到其他机器_有赞大数据离线集群迁移实战

    ‍‍ 点击关注"有赞coder" 获取更多技术干货哦- 作者:郭理想 & 任海潮部门:数据中台 一.背景 有赞是一家商家服务公司,向商家提供强大的基于社交网络的,全渠道经营 ...

  3. 大数据离线阶段--数据获取

    大数据离线阶段 -----数据获取原理 数据分析 1. 数据分析定义 数据分析离不开数据,计量和记录一起促成了数据的诞生.伴随着数据记录的发展(尤其是技术),人类受益也越来越多,计算机出现带来的数字测 ...

  4. 大数据技术之Hive(二)Hive入门

    一.Hive入门 1.1 Hive简介 1.1.1 hive出现的原因 FaceBook网站每天产生海量的结构化日志数据,为了对这些数据进行管理,并且因为机器学习的需求,产生了hive这门技术,并继续 ...

  5. OPPO大数据离线计算平台架构演进

    1 前言 OPPO的大数据离线计算发展,经历了哪些阶段?在生产中遇到哪些经典的大数据问题?我们是怎么解决的,从中有哪些架构上的升级演进?未来的OPPO离线平台有哪些方向规划?今天会给大家一一揭秘. 2 ...

  6. OPPO大数据离线任务调度系统OFLOW

    1 离线调度系统 在整个大数据体系中,在原始数据被采集之后,需要使用各种逻辑进行整合和计算之后才能输出实际有效的数据,才能最终用于商业目的,实现大数据的价值.在整个处理流程中,无论是抽取.转换.装载( ...

  7. 大数据建模流程之任务分析

    上一篇文章我们简单阐述了,大多数研究者在进行大数据分析时,所存在的逻辑问题,并简明扼要的对大数据建模流程进行了说明,那么为了使大家更加清晰每一个步骤的具体内容,我们将每一个模块展开分析.详细阐述流程中 ...

  8. 大数据时代的小数据会消亡吗(非原创)

    大数据时代的小数据会消亡吗 苏令银 上海师范大学马克思主义学院 上海师范大学经济伦理研究中心 摘 要: 在过去的几个世纪,学术知识的构建普遍使用小数据并取得了巨大进步,其特征是为回答特定问题而生成的抽 ...

  9. 大数据离线集群数据迁移实战项目

    有赞大数据离线集群迁移实战 一.背景 有赞是一家商家服务公司,向商家提供强大的基于社交网络的,全渠道经营的 SaaS 系统和一体化新零售解决方案.随着近年来社交电商的火爆,有赞大数据集群一直处于快速增 ...

最新文章

  1. HDFS namenode 高可用(HA)搭建指南 QJM方式 ——本质是多个namenode选举master,用paxos实现一致性...
  2. androidx86安装pc后无法联网_问题解决记录-npm和yarn全局安装成功后命令无法执行的问题...
  3. hj212协议如何和php通讯,HJ212数据传输标准报文解析
  4. 贷款,别相信这些人!
  5. springboot redis token_Spring Boot + Redis + 注解 + 拦截器来实现接口幂等性校验
  6. python dataframe 列_python pandas库中DataFrame对行和列的操作实例讲解
  7. linux cat时间段,linux – cat / dev / urandom的输出是多么临时
  8. 1024程序员日,互联网公司们福利感人;支付宝36万招“找茬”程序员
  9. 如何优雅的统计代码耗时,快速知道你的程序慢在哪里!
  10. 常见泰勒展开公式及复杂泰勒展开求法
  11. 文档大小超出上传限制怎么办_有道翻译和翻译狗,哪个更适合翻译文档?
  12. 什么是生物质发电?生物质发电有哪些方法?
  13. 黑客攻防专题九:菜鸟 Sa 注入=肉鸡
  14. xamp设置web服务器
  15. skip gram模型的实现
  16. 2018/12/22
  17. 用C语言写俄罗斯方块
  18. glyphicons 图标大全
  19. mysql练习-数据库安全性与完整性
  20. 《编程之美》读书笔记23: 1.1 让CPU占用率曲线听你指挥

热门文章

  1. 阴阳师服务器维护2月20,阴阳师体验服2月20日更新了什么 2.20更新维护公告
  2. 超好玩的神乐七奈桌面宠物+有BGM音效
  3. mysql必知必会的数据_MySQL必知必会--汇 总 数 据
  4. nn.BatchNorm2d() 手推计算步骤
  5. poj解题报告——2325
  6. Cordova 开发之安卓插件开发(二)
  7. Ten 使用ssh服务管理远程主机
  8. mhw跳过结尾_怪物猎人世界怎么刷珠子快 MHW刷珠子炼金SL大法
  9. c# 方法参数(传值,传引用,ref,out,params,可选参数,命名参数)
  10. 关于“与google服务器通信时出现问题“