大数据全系列 教程
1869个小节阅读:467.6k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
需求:找出掉话率最高的前10基站
创建原始数据表:
xxxxxxxxxx
create table jizhan(
record_time string,
imei int,
cell string,
ph_num int,
call_num int,
drop_num int,
duration int,
drop_rate double,
net_type string,
erl int)
row format delimited fields terminated by ',';
字段描述:
xxxxxxxxxx
record_time:通话时间
imei:基站编号
cell:手机编号
drop_num:掉话的秒数
duration:通话持续总秒数
创建结果表:
xxxxxxxxxx
create table jizhan_result(
imei string,
drop_num int,
duration int,
drop_rate double
);
数据文件准备:
首先将软件/data/cdr_summ_imei_cell_info.csv上传到node4上/root/data目录下,将第一行的表头数据删除
然后load到hive的jizhan表中。
xxxxxxxxxx
hive> load data local inpath '/root/data/cdr_summ_imei_cell_info.csv' into table jizhan;
Loading data to table default.jizhan
OK
Time taken: 2.734 seconds
hive> select * from jizhan limit 10;
OK
2011-07-13 00:00:00+08 356966 29448-37062 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 352024 29448-51331 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 353736 29448-51331 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 353736 29448-51333 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 351545 29448-51333 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 353736 29448-51343 1 0 0 8 0.0 0
2011-07-13 00:00:00+08 359681 29448-51462 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 354707 29448-51462 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 356137 29448-51470 0 0 0 0 0.0 0
2011-07-13 00:00:00+08 352739 29448-51971 0 0 0 0 0.0 0
Time taken: 0.338 seconds, Fetched: 10 row(s)
hive> select count(*) from jizhan;
976305
编写分析的sql语句
xxxxxxxxxx
select imei,sum(drop_num) sdrop,sum(duration) sdura,sum(drop_num)/sum(duration) drop_rate
from jizhan
group by imei
order by drop_rate desc;
将分析的结果写入到jizhan_result表中:
xxxxxxxxxx
from jizhan
insert into jizhan_result
select imei,sum(drop_num) sdrop,sum(duration) sdura,sum(drop_num)/sum(duration) drop_rate
group by imei
order by drop_rate desc;
查询结果表,获取前10条数据,也就掉话率最高的前10个基站:
xxxxxxxxxx
hive> select * from jizhan_result limit 10;
OK
639876 1 734 0.0013623978201634877
356436 1 1028 9.727626459143969E-4
351760 1 1232 8.116883116883117E-4
368883 1 1448 6.906077348066298E-4
358849 1 1469 6.807351940095302E-4
358231 1 1613 6.199628022318661E-4
863738 2 3343 5.982650314089142E-4
865011 1 1864 5.36480686695279E-4
862242 1 1913 5.227391531625719E-4
350301 2 3998 5.002501250625312E-4