数据仓库分层:DWS层设计
数据建模入门数据建模数据仓库
问题
DWS(汇总数据层)的作用是什么?如何设计汇总粒度?
答题要点
DWS是轻度聚合层,预计算常用汇总,加速查询。
设计原则:
1. 确定汇总粒度 基于查询频率和性能需求:
- 日汇总:dws_sales_daily
- 周汇总:dws_sales_weekly
- 月汇总:dws_sales_monthly
2. 汇总维度组合
-- 示例:每日产品销售汇总
CREATE TABLE dws_sales_product_daily (
date_key INT,
product_key BIGINT,
-- 汇总指标
order_count INT,
customer_count INT,
total_quantity INT,
total_sales DECIMAL(15,2),
total_cost DECIMAL(15,2),
total_profit DECIMAL(15,2),
avg_unit_price DECIMAL(10,2),
PRIMARY KEY (date_key, product_key)
);
-- 示例:每日客户分群汇总
CREATE TABLE dws_sales_segment_daily (
date_key INT,
customer_segment VARCHAR(50),
region VARCHAR(50),
-- 汇总指标
customer_count INT,
order_count INT,
total_sales DECIMAL(15,2),
avg_order_value DECIMAL(10,2),
PRIMARY KEY (date_key, customer_segment, region)
);
3. 增量更新
- T+1每天更新昨日数据
- 只刷新变化分区
- 保留历史汇总
完整解析在题库里看
核心知识点、易错点和面试官想听到什么;练过的题会进入记录,答错的进错题本。
去练这道题