一、目的
在完成数据之后对业务指标进行分析,Hive和ClickHouseSQL真不一样
二、部分业务指标表
2.1 统计数据流量表1天周期
2.1.1 Hive中原有代码
2.1.1.1 Hive中建表语句
--1、统计数据流量表——动态分区——1天周期 create table if not exists hurys_db.dws_statistics_volume_1day( device_no string comment '设备编号', scene_name string comment '场景名称', lane_no int comment '车道编号', lane_direction string comment '车道流向', section_no int comment '断面编号', device_direction string comment '雷达朝向', sum_volume_day int comment '每天总流量', week_day string comment '周几', month string comment '月份' ) comment '统计数据流量表——动态分区——1天周期' partitioned by (day string) stored as orc ;
2.1.1.2 Hive中SQL语句
--动态加载数据 insert overwrite table hurys_db.dws_statistics_volume_1day partition(day) select dwd_st.device_no, dwd_sc.scene_name, dwd_st.lane_no, dwd_rl.lane_direction, dwd_st.section_no, dwd_rc.device_direction, sum(volume_sum) sum_volume_day, case when pmod(datediff(create_time,'2023-11-27') + 1,7) = 1 then '周一' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 2 then '周二' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 3 then '周三' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 4 then '周四' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 5 then '周五' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 6 then '周六' else '周日' end as week_day, substr(day,1,7) month, day from hurys_db.dwd_statistics as dwd_st right join hurys_db.dwd_radar_lane as dwd_rl on dwd_rl.device_no=dwd_st.device_no and dwd_rl.lane_no=dwd_st.lane_no right join hurys_db.dwd_device_scene as dwd_ds on dwd_ds.device_no=dwd_st.device_no right join hurys_db.dwd_scene as dwd_sc on dwd_sc.scene_id = dwd_ds.scene_id right join hurys_db.dwd_radar_config as dwd_rc on dwd_rc.device_no=dwd_st.device_no where dwd_st.create_time is not null and dwd_st.day='2024-09-05' group by dwd_st.device_no, dwd_sc.scene_name, dwd_st.lane_no, dwd_rl.lane_direction, dwd_st.section_no, dwd_rc.device_direction, case when pmod(datediff(create_time,'2023-11-27') + 1,7) = 1 then '周一' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 2 then '周二' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 3 then '周三' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 4 then '周四' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 5 then '周五' when pmod(datediff(create_time,'2023-11-27') + 1,7) = 6 then '周六' else '周日' end, day ;
2.1.2 ClickHouse中现有代码
2.1.2.1 ClickHouse中表结构
--1、统计数据流量表——动态分区——1天周期 cre