数仓理论知识
1. 数仓分层
为什么分层:
1:清洗数据结构:每一个数据分层都哦于他的作用域和职责,在使用表的时候能更方便定位和理解
2:统一开发:减少重复开发;规范数据分层,开发一些通用的中间层数据,能够减少极大的重复计算
3:统一数据口径:通过数据分层,提供统一的数据出口,统一对外输出的数据口径
4:复杂问题简单化:将一个复杂的任务分解成多个步骤来完成,每一个层解决特定的问题
-
ODS层 Operational Data Store
ETL后的数据进ODS层
或不清洗:方便追溯数据 -
DWD层 Data Warehouse Detail
ODS层按主体建造数据模型(业务表示) -
APP层 Application
最终提供给用户使用
提供给数据产品和数据分析使用的数据
2. 数据追溯
???如果ETL数据直接进ODS层
错误日志收集 , 计数
3. 现实
-
ODS层 Operational Data Store
(文本格式) =-= 大数据用的不多,用列式存储; -
DWD层 Data Warehouse Detail d
(ORC/Parquet)
压缩
体积 小很多 -
DWS层 Data Warehouse Server d
汇总操作
轻度汇总 -
APP层 Application d
题外话 . hive 建表分区
create table ods_traffic_table(
ip string,
proxy string,
response_time int,
referer string,
method string,
url string,
http_code string,
request_size int,
response_size int,
cache string,
province string,
city string,
isp string,
http string,
domain string,
path string,
year string,
month string,
day string
)partitioned by (d string)
row format delimited fields terminated by '\t';
alter table ods_traffic_table add if not exists partition(d='20200523') location '20200523';
load data local inpath '/home/hadoop/app/ruozedata-dw/data/part-m-00000' overwrite into table ods_traffic_table partition(d='20200523');
ALTER TABLE ods_traffic_table RENAME TO ods_access;
#!/bin/sh
time=20200523
echo "省份流量统计"
hive -e "
use ruozedata_dw;
create table if not exists dws_access_province_traffic(
province string,
traffics int
)partitioned by(d string)
row format delimited fields terminated by '\t';
insert overwrite table ruozedata_dw.dws_access_province_traffic partition(d='$time')
select province, sum(response_size) as traffics
from ods_access where d='$time' group by province;
"
#!/bin/sh
time=20200523
echo "域名流量统计"
hive -e "
use ruozedata_dw;
create table if not exists dws_access_domain_traffic(
domain string,
traffics int
)partitioned by(d string)
row format delimited fields terminated by '\t';
insert overwrite table ruozedata_dw.dws_access_domain_traffic partition(d='20200523')
select domain, sum(response_size) as traffics
from ods_access where d='$time' group by domain;
"
面试经典 . 数据量
1)每天数据量
每条日志多大 字节 300-500
有多少条 1000W用户 * 5次 * 5
每条日志多少字段:50-70字段
总数据量
(300-500 * 1000W * 5 )/(1024 * 1024 * 1024) == 70-116G
2)每天增量
3)70 - 116 G * 3副本 * 365 *3 = 224~372T 数据
4)ODS + DWD + DWS + APP =
5)10 条业务线 有大有小
==> 明年预算 加多少机器 20%-30%预留
6)一个业务线 多少个job
mr + sql