详解:离线项目二 每个区域下最受欢迎的产品TOPN
项目需求:统计每个区域下最受欢迎的产品TOP3 ==> TOPN
最终我们要得到哪些数据
一:离线典型的处理框架
人 ——京东页面 ——webserver(集群,这里记录你的 操作所以行为日志 )—— 通过flume采集——hadoop的hdfs 上面存储 ——数据分析 mp/hive/spark(这里的数据存储还是在hdfs上面)——你要做前端的展示 就要(通过 用Sqoop )数据存储在ROBMS /NoSQL上面 ——UI展示
二:前期准备工作
在之前的这篇博客中:https://blog.csdn.net/qq_43688472/article/details/94454720
我们已经介绍了我的用户行为数据都已经被记录下来了
1第一步清洗数据
我们要对用户行为数据 log.gif 进行清洗 筛选出我们需要的数据(因为数据量很大,我们只要根据我们的需求,拿出相应的数据就可以了,没有必要大规模处理,清洗过后的数据我们看着简单明了 更方便处理)清洗数据永远都是第一步
2第二步将数据形成表格
这里我把数据表格 分别放在mysql和hive中
[root@hadoop001 ~]# su - mysqladmin
Last login: Fri Jun 28 10:01:25 CST 2019 on pts/3
[mysqladmin@hadoop001 ~]$ mysql -uroot -pmysql> create database ruozedata5;
Query OK, 1 row affected (0.00 sec)mysql> use ruozedata5;
Database changed
mysql> show tables;
Empty set (0.00 sec)创建产品表
mysql>CREATE TABLE `product_info` (`product_id` int(11) DEFAULT NULL,`product_name` varchar(255) DEFAULT NULL,`extend_info` varchar(1000) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
这里要导入相应的数据
这里在hive里面有点击次数的数据
create table user_click(
user_id int,
session_id string,
action_time string,
city_id int,
product_id int
) partitioned by(date string)
row format delimited fields terminated by ',';
3.把相关的表格都放到一起
1)Hive中要创建city_info, product_info
create table city_info(
city_id int,
city_name string,
area string
)
row format delimited fields terminated by '\t';create table product_info(
product_id int,
product_name string,
extend_info string
)
row format delimited fields terminated by '\t';因为目前的数据,有的在hive有的在mysql中,首先把mysql中的数据导入到hive中 来在这之前先把表格创建出来
2)MySQL==>Hive sqoop import \
--connect jdbc:mysql://localhost:3306/ruozedata5 \
--username root \
--password root \
--table product_info \
--mapreduce-job-name FromMySQLToHDFS \
-m 1 \
--delete-target-dir \
--fields-terminated-by '\t' \
--null-non-string '0' \
--null-string '' \
--hive-import \
--hive-table product_info \
--hive-overwrite
在生产上面用shell脚本来封装的
三:操作(重点)
第一步:user_click join city_infocreate table tmp_product_click_basic_info
as
select
u.product_id, u.city_id, c.city_name, c.area
from
(select product_id, city_id from user_click
where date='2016-05-05'
and product_id <> 0) u
join
(select city_id,city_name, area from city_info) c
on u.city_id = c.city_id;各个区域各商品的点击次数drop table tmp_area_product_click_count;
create table tmp_area_product_click_count as
select product_id,area,count(1) as click_count from tmp_product_click_basic_info group by product_id,area;1 NC 8
1 NW 6
1 SC 25create table tmp_area_product_click_count_full_info as
select a.product_id,b.product_name,a.click_count, a.area from tmp_area_product_click_count a join product_info b on a.product_id=b.product_id;求每个区域下最受欢迎的top3create table area_product_click_count_top3
as
select *,
case when click_count >=10 and click_count<20 then 'lower'
when click_count>=20 and click_count<30 then 'middle'
else 'highest'
end click_count_grade,
'2016-05-05' day
from (
select
product_id,product_name,click_count,area,
row_number() over(partition by area order by click_count desc) rank
from tmp_area_product_click_count_full_info
) t where t.rank <=3 ;
注意:要详细理解sql语句的意思,不行可以慢慢拆分来处理
最后在合在一起
四:将结果写到mysql中
这里也是用到Sqoop导到进去就可以了
五:UI展示
下面的UI展示,就交给前端人员吧
我的大数据开发就到这里为止了
六:优化
1.把mysql语句封装成shell脚本这样操作就很方便的
2.使用这个 hive -e
就不需要进入hive 在外面可以执行hive的相关语句
$hive -e "show databaases"
3.其中在shell语句中
get_json_object 不要使用这个来解析
因为这里是测试,可以数据量少可以使用
但是在大数据的环境下 数据量庞大,这里就不适用了
那怎么办呢
通过 自定义解析JSON的UDF函数 <== 使用Java开发Hive的UDF函数来搞定
这个在后面会介绍的
详解:离线项目二 每个区域下最受欢迎的产品TOPN相关推荐
- 《视频直播技术详解》之二:编码和封装、推流和传输
视频编码是本系列一个重要的部分,如果把整个流媒体比喻成一个物流系统,那么编解码就是其中配货和装货的过程,这个过程非常重要,它的速度和压缩比对物流系统的意义非常大,影响物流系统的整体速度和成本.同样,对 ...
- shell脚本详解(十二)——Here Document免交互及Expect自动化交互
shell脚本详解(十二)--Here Document免交互及Expect自动化交互 一.Here Document 免交互 1.格式 2.注意事项 3.免交互方式实现对行数的统计,将要统计的内容置 ...
- java调用项目中的文件_详解eclipse项目中.classpath文件的使用
1 前言 在使用eclipse或者myeclipse进行java项目开发的时候,每个project(工程)下面都会有一个.classpath文件,那么这个文件究竟有什么作用? 2 作用 .classp ...
- CMake手册详解 (十二)
2019独角兽企业重金招聘Python工程师标准>>> SirDigit CMake手册详解 (十二) CMD#30:find_library查找一个库文件 find_library ...
- AT指令(中文详解版)(二)
AT指令(中文详解版)(二) 常 用 AT 命 令 手 册 1.常用操作 1.1 AT 命令解释:检测 Module 与串口是否连通,能否接收 AT 命令: 命令格式:AT<CR> 命 ...
- 详解 Python qrcode 二维码模块
原文链接 摘要: 详解 Python qrcode 二维码模块. 项目地址 https://github.com/lincolnloop/python-qrcode 声明 importqrcode 使 ...
- 详解uni-app项目运行在ios模拟器调试
详解uni-app项目运行在ios模拟器调试 uni-app项目运行在ios模拟器调试 文章目录 详解uni-app项目运行在ios模拟器调试 前言 一.环境准备 二.模拟器调试 总结 前言 UNI- ...
- 《 Python List列表全实例详解系列(二)》__创建列表(5种方式)
< Python List列表全实例详解系列(二)> __创建列表(5种方式) 上一篇:< Python List 列表全实例详解系列(一)>__系列总目录.列表概念 本章目录 ...
- 「软件项目管理」一文详解软件项目质量计划
一文详解软件项目质量计划
最新文章
- openfire安装配置完全教程
- scrum与第一次teamwork
- 充满含金量的一场云原生Meetup,入场券免费发送中……
- 最大子矩阵问题悬线法 学习小结
- radvd移植到arm交叉编译问题解决
- 用c语言elgamal共密钥密码加密算法,非对称密钥体制RSA加密原理
- IT人不要一辈子靠技术生存
- Intro to Xamarin.Android Xamarin Android入门教程 Lynda课程中文字幕
- css引入矢量图标_一张矢量图使用css来调用矢量图里的N个图标
- 基于SVM的手写字体识别
- EXCEL数组公式,群里求助的问题,按条件查最大值,中位数等, 可用数组公式解决
- P2339 [USACO04OPEN]Turning in Homework G 笔记/题解
- 如何只用一个软件制作大屏图表
- 航空摄影与正射摄影的区别
- 时区提示:Local time zone must be set--see zic manual page 2018的解决办法
- 信息安全系统和安全体系
- Cad二次开发小工具
- 2022 最值得学习的编程语言:Python 高人气,Ruby 薪水最优渥
- HTML利用posotion属性定位 小技巧
- 飞塔防火墙固定IP改动态IP网络设置