Hive+Sqoop+Mysql整合

本文详细介绍了监控点、摄像头的状态管理流程,包括数据格式、测试数据生成、以及在Hive中创建并导入数据到相关表格的过程。通过这些步骤,可以有效地进行监控数据的收集与分析。

答:监控点/摄像头状态

工作流程如下:

1.数据格式

/ **
 *产生测试数据:
 *数据格式:
 *记录时间车牌号码车速道路编号监控地点摄像头编号
 * date_time vehicle_plate vehicle_speed road_id monitor_id camera_id
 * 
 *中间使用'\ t'隔开
 * 16/01/2019 10:20 :30 SCN89000J 124 10002 20004 40007
 * 
 *具体说明:
 *道路编号
 * 10001 - 10100
 * 
 *监控地点 - 在一条道路上面有2个监控点
 * 20001 - 20200
 * 
 *摄像头编号 - 在一个监控点上面2个摄像头
 * 40001 - 40400
 * 
 *道路:10001 10002
 *监控:20001-20002 20003-20004
 *摄像头:40001-40002-40003-40004 40005-40006-40007-40008

 * 
 *车速:1-300如果大于260,则为超速行驶
 * 
 *车牌:SCN89000J
 * 
 *记录时间:16/01/2019十点二十分30秒 
 * 
 * /

2.生成测试数据

--编译运行java code
cd /root/vehicle_dir/

vi DataGenerate.java

DataGenerate.java

--运行完生成两个文件:
/root/vehicle_dir/vehicle_log
/root/vehicle_dir/road_monitor_camera_relationship

2.2。车辆记录日志样本

实际监测到的数据

记录时间                 车牌号码         车速       道路编号   监控地点      摄像头编号
date_time              car_plate      car_speed    road_id   monitor_id    camera_id

16/01/2019 14:06:44    SVM35185L        258        10295      20590        41179
16/01/2019 15:56:25    SVM35185L        110        10288      20575        41149
16/01/2019 02:22:29    SVM35185L        28         10109      20217        40436
16/01/2019 24:29:59    SSK43417H        254        10281      20562        41123
16/01/2019 07:36:54    SSK43417H        149        10124      20247        40495
16/01/2019 12:21:30    SSK43417H        196        10211      20421        40843
16/01/2019 12:42:43    SSK43417H        92         10308      20615        41230
16/01/2019 02:57:59    SDV20274X        206        10166      20332        40663
16/01/2019 11:60:17    SDV20274X        191        10372      20744        41488
16/01/2019 00:09:06    SDV20274X        197        10094      20188        40374
16/01/2019 21:18:30    SDV20274X        294        10101      20201        40401
16/01/2019 11:23:38    SDV20274X        74         10163      20325        40652
16/01/2019 04:35:16    SDV20274X        53         10077      20153        40305
16/01/2019 20:56:56    SDV20274X        31         10113      20226        40449
16/01/2019 16:50:11    SEN89218Y        58         10202      20404        40808
16/01/2019 18:34:47    SEN89218Y        113        10042      20083        40168
16/01/2019 02:25:52    SEN89218Y        35         10051      20101        40204
16/01/2019 24:08:52    SEN89218Y        77         10165      20330        40657

2.3道路 - 监控 - 摄像头关系样本

道路            监控        摄像头
road         monitor      camera

10001        20001        40001
10001        20001        40002
10001        20002        40003
10001        20002        40004
10002        20003        40005
10002        20003        40006
10002        20004        40007
10002        20004        40008
10003        20005        40009
10003        20005        40010
10003        20006        40011
10003        20006        40012
10004        20007        40013
10004        20007        40014
10004        20008        40015
10004        20008        40016

3.在蜂巢中创建表并且导入数据

建表:t_vehicle_log(用来记录实际监控信息的表)

-- 创建table,并且把结果数据导入到Hive table里面
vi /root/vehicle_dir/hive_vehicle.sql


--1.drop t_vehicle_log
drop table IF EXISTS t_vehicle_log;

--2.create t_vehicle_log
CREATE TABLE t_vehicle_log(
date_time string ,      -- 时间
vehicle_plate string ,  -- 车牌
vehicle_speed int ,     -- 车速
road_id string ,        -- 道路
monitor_id string ,     -- 监控
camera_id string        -- 摄像头
)ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n';

--3.load data into t_vehicle_log
load data local inpath '/root/vehicle_dir/vehicle_log' into table t_vehicle_log;

建表:t_road_monitor_camera_relationship(真实的路口,监控,摄像头的关系)

--4.drop t_road_monitor_camera_relationship
drop table IF EXISTS t_road_monitor_camera_relationship;

--5.create t_road_monitor_camera_relationship
CREATE TABLE t_road_monitor_camera_relationship(
road_id string ,
monitor_id string ,
camera_id string
)ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n';

--6.load data into t_road_monitor_camera_relationship
load data local inpath '/root/vehicle_dir/road_monitor_camera_relationship' into table t_road_monitor_camera_relationship;

建表:t_monitor_camera监控正常的摄像头个数不正常的摄像头个数

--7.drop t_monitor_camera
drop table IF EXISTS t_monitor_camera;

--8.create t_monitor_camera
create table t_monitor_camera(
monitor_id string ,
cameranum int,
workingcameranum int,
notWorkingCameraNum int
)ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n';

--9.load data from other table into t_monitor_camera
from (select monitor_id, count(distinct camera_id) cameraNum from t_road_monitor_camera_relationship group by monitor_id) t1 
left outer join 
(select monitor_id, NVL(count(distinct camera_id), 0) workingCameraNum from t_vehicle_log group by monitor_id) t2
on t1.monitor_id=t2.monitor_id
insert into table t_monitor_camera
select t1.monitor_id, t1.cameraNum cameraNum, NVL(t2.workingCameraNum, 0) workingCameraNum,NVL((t1.cameraNum - NVL(t2.workingCameraNum, 0)), 0) notWorkingCameraNum;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值