二百六十五、Hive——目前Hive数仓各层表样例

ops/2024/9/23 1:58:56/

一、目的

梳理一下目前Hive数仓各层表

注意:只建立一个数据库hurys_db

二、ODS层

2.1 建表语句

create external table  if not exists  hurys_db.ods_queue(device_no           string          comment '设备编号',source_device_type  string          comment '设备类型',sn                  string          comment '设备序列号 ',model               string          comment '设备型号',create_time         string          comment '创建时间',lane_no             int             comment '车道编号',lane_type           int             comment '车道类型 0:渠化1:来向2:出口3:去向4:左弯待转区5:直行待行区6:右转专用道99:未定义车道',queue_count         int             comment '排队车辆数',queue_len           float           comment '排队长度(m)',queue_head          float           comment '排队头车距停止线距离(m)',queue_tail          float           comment '排队尾车距停止线距离(m)'
)
comment '静态排队数据外部表——静态分区'
partitioned by (day string)
row format delimited fields terminated by ','
stored as SequenceFile
;

2.2 SQL语句

--刷新表分区
msck repair table ods_queue;
--查看表分区
show partitions ods_queue;
--查看表数据
select * from ods_queue;

三、DWD层

3.1 脱敏清洗表

3.1.1 建表语句

create  table  if  not exists  hurys_db.dwd_queue(id                  string          comment '唯一ID',device_no           string          comment '设备编号',source_device_type  string          comment '设备类型',sn                  string          comment '设备序列号 ',model               string          comment '设备型号',create_time         string       comment '创建时间',lane_no             int             comment '车道编号',lane_type           int             comment '车道类型 0:渠化1:来向2:出口3:去向4:左弯待转区5:直行待行区6:右转专用道99:未定义车道',queue_count         int             comment '排队车辆数',queue_len           decimal(10,2)   comment '排队长度(m)',queue_head          decimal(10,2)   comment '排队头车距停止线距离(m)',queue_tail          decimal(10,2)   comment '排队尾车距停止线距离(m)'
)
comment '静态排队数据表——动态分区'
partitioned by (day string)
stored as orc
;

3.1.2 SQL语句

with t1 as (
selectdevice_no,source_device_type,sn,model,create_time,lane_no,lane_type,case when  queue_count  is null then 0 else queue_count  end as  queue_count,case when  queue_len    is null then 0 else cast(queue_len   as decimal(10,2))  end as     queue_len,case when  queue_head   is null then 0 else cast(queue_head  as decimal(10,2))  end as     queue_head,case when  queue_tail   is null then 0 else cast(queue_tail  as decimal(10,2))  end as     queue_tail,substr(create_time,1,10)  day
from hurys_db.ods_queue
where   day = '2024-09-10'
)
insert  overwrite  table  hurys_db.dwd_queue partition(day)
selectUUID()  as  id,device_no,source_device_type,sn,model,create_time,lane_no,lane_type,queue_count,queue_len,queue_head,queue_tail,day
from t1
where   day = '2024-09-10' and  device_no is not null  and create_time is not null
and  queue_len  between 0  and 500   and  queue_head   between 0 and 500   and lane_no between 0 and 255
and  queue_tail between 0  and 500   and  queue_count  between 0 and 100
group by device_no, source_device_type, sn, model, create_time, lane_no, lane_type, queue_count, queue_len, queue_head, queue_tail, day
;
--查看分区
show partitions hurys_db.dwd_queue;
--查看数据
select * from hurys_db.dwd_queue
where day='2024-09-10';
--删掉表分区
alter table hurys_db.dwd_queue drop partition (day='2024-09-04');

四、维度表

4.1 节假日表

4.1.1 原始表建表语句

create external  table  if not exists  hurys_db.tb_holiday(id       int     comment '主键id',day      date    comment '日期',holiday  string  comment '节假日',year     string  comment '年份'
)
comment '节假日表'
row format delimited fields terminated by ','
stored as  textfile  location '/data/tb_holiday'
tblproperties("skip.header.line.count"="1") ;

4.1.2 清洗表建表语句

create table if not exists  hurys_db.dwd_holiday(day      date    comment '日期',holiday  string  comment '节假日',year     string  comment '年份'
)
comment '节假日表'
stored as orc
;

五、DWS层

5.1 统计数据流量表——动态分区——1天周期

5.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
;

5.1.2 SQL语句

insert  overwrite  table  hurys_db.dws_statistics_volume_1day  partition(day)
selectdwd_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_stright join hurys_db.dwd_radar_lane as dwd_rlon dwd_rl.device_no=dwd_st.device_no and dwd_rl.lane_no=dwd_st.lane_noright join hurys_db.dwd_device_scene as dwd_dson dwd_ds.device_no=dwd_st.device_noright join hurys_db.dwd_scene as dwd_scon dwd_sc.scene_id = dwd_ds.scene_idright join hurys_db.dwd_radar_config as dwd_rcon 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
;

这就是目前数仓各层的表样例,这边只是逻辑分层,并没有给每一层建立一个单独的数据库,那样在多层的表联合查询时速度会相比慢很多!!!


http://www.ppmy.cn/ops/114526.html

相关文章

docker 镜像,导入导出,

dockers镜像传输:docker save和docker load命令的使用_docker save -o-CSDN博客 docker save 命令 docker load 命令 快速复制容器-CSDN博客 创建docker容器报错:Error response from daemon: No command specified-CSDN博客 Docker 镜像移动或复制到另一台服务器_d…

网络编程问题解答

TCP/IP是哪种模型的协议 TCP/IP 是一组通信协议的集合,它基于 TCP/IP 模型。TCP/IP 模型通常被认为是一种实用的网络通信模型,与 OSI 模型相比,TCP/IP 模型更加简洁和侧重于实际应用,被广泛应用于互联网和大多数计算机网络中。 T…

论文阅读--Planning-oriented Autonomous Driving(二)

自动驾驶框架的各种设计比较。 ( a )大多数工业解决方案针对不同的任务部署不同的模型。 ( b )多任务学习方案共享一个具有分割任务头的主干。 ( c )端到端范式将感知和预测模块统一起来。以往的尝试要么采用( c.1 )中对规划的直接优化,要么采用( c.2 )中的部分元…

LangChain教程 - 支持的向量数据库列举

系列文章索引 LangChain教程 - 系列文章 向量数据库是现代自然语言处理应用中不可或缺的组件,它们可以高效地存储、索引和检索嵌入向量,支持大规模的相似性搜索任务。LangChain 是一个强大的框架,允许开发者轻松将大型语言模型与向量数据库结…

单组件的编写

项目搭好了,第一个需要了解的是 Vue 组件的变化,由于这部分篇幅会非常大,所以会分成很多个小节,一部分一部分按照开发顺序来逐步了解。 因为 Vue 3 对 TypeScript 的支持真的是太完善了,并且 TypeScript 的发展趋势和…

科技引领未来生活——“光影漫游者”展览馆应用—轻空间

随着科技的快速发展,展览馆作为展示文化、科技和艺术的场所,正逐渐从传统的静态展示向高科技互动体验转变。由轻空间打造的“光影漫游者”展览馆,凭借其前沿的气承式结构和智能化系统,将参观者带入了一个未来感十足、充满科技魅力…

深度学习02-pytorch-02-张量的拼接操作

在 PyTorch 中,张量的拼接操作可以通过以下几种主要方法来实现,最常用的包括 torch.cat(), torch.stack(), 以及 torch.chunk()。这些操作可以将多个张量沿某个维度拼接在一起或拆分张量。下面将详细介绍如何使用这些操作。 1. torch.cat() torch.cat(…

星火AI图片理解API文档

图片理解 API 文档 | 讯飞开放平台文档中心 接口说明 用户输入一张图片和问题,从而识别出图片中的对象、场景等信息回答用户的问题 部分开发语言demo如下,其他开发语言请参照文档进行开发,也欢迎热心的开发者到 讯飞开放平台社区 分享你们的…