数仓基础入门-10-实践篇

本文提供了一个简单的数仓订单主题构建的demo,包括ods、dwd、dim和dws层的表设计。通过实例展示了如何处理日志表、用户信息、SKU详情和店铺详情,以及在不同层中进行字段修改和聚合操作,帮助初学者理解数仓模型设计。
摘要由CSDN通过智能技术生成

有不少没涉及过数仓的同学问我一些比较基础的问题,为了更好的理解前面讲到的一些理论,写一个小小的demo体会一下~~
我们要构建一个订单主题,构建订单明细,订单sku,订单粒度三张表。(假设我们只有一个数据域,单纯的为了举个例子,有一个大概的理解)
模型设计及概念可阅读《数仓基础入门》系列历史文章,三言两语就打发了,具体深意自己体会~😝
ods层表
日志表:ods_order_detail_logs_di

字段字段含义字段类型
dt日期string
log_time日志时间string
order_id订单idstring
user_id用户idstring
store_id店铺idstring
sku_detail商品列表string
address地址string
order_price结算金额decimal(28,6)
dicount_price折扣金额decimal(28,6)

user库下user_info表:ods_user_user_info_di

字段字段含义字段类型
dt日期string
user_id用户idstring
name用户昵称string
gender性别tinyint
age年龄int

sku库下sku_detail表:ods_sku_sku_detail_di

字段字段含义字段类型
dt日期string
sku_id商品idstring
name商品名称string
category_id分类idstring
category_name分类名称string
unit_price单价decimal(28,6)

shop库下shop_detail表:ods_shop_shop_detail_di

字段字段含义字段类型
dt日期string
shop_id商铺idstring
name商铺名称string
industry_id行业idstring
industry_name行业名称string
phone联系电话string

模型设计如下:

8940211-452bb0b63e288aa4.png
模型设计

每张表的结构及逻辑如下:
dwd层表
表:dwd_order_detail_logs_di
处理点:

  • 修改store_id 为shop_id,统一字段
  • 解析address结构 国家,省份,城市,街道详细信息
  • 解析sku_detail,分摊每个sku价格
字段字段含义字段类型
dt日期string
log_time日志时间string
order_id订单idstring
user_id用户idstring
shop_id店铺idstring
sku_id商品idstring
country_id国家idstring
province_id省份idstring
city_id城市idstring
street_address街道详细地址string
order_price结算金额decimal(28,6)
dicount_price折扣金额decimal(28,6)

dim层表
1.dim_user_info

  • 处理点:字段name修改
字段字段含义字段类型
dt日期string
user_id用户idstring
user_name用户昵称string
gender性别tinyint
age年龄int

2.dim_sku_info

  • 处理点:字段name,unit_price修改
字段字段含义字段类型
dt日期string
sku_id商品idstring
sku_name商品名称string
category_id分类idstring
category_name分类名称string
sku_unit_price商品单价decimal(28,6)

3.dim_shop_info

  • 处理点:字段name,phone修改
字段字段含义字段类型
dt日期string
shop_id商铺idstring
shop_name商铺名称string
industry_id行业idstring
industry_name行业名称string
shop_phone商铺联系电话string

dws层
dws_order_detail_di

  • 处理点:退化维度到事实表,删掉不必要字段log_time
  • 唯一键:concat(order_id,sku_id)
字段字段含义字段类型
dt日期string
order_id订单idstring
user_id用户idstring
user_name用户昵称string
gender性别tinyint
age年龄int
shop_id店铺idstring
shop_name商铺名称string
industry_id行业idstring
industry_name行业名称string
shop_phone商铺联系电话string
sku_id商品idstring
sku_name商品名称string
category_id分类idstring
category_name分类名称string
sku_unit_price商品单价decimal(28,6)
country_id国家idstring
province_id省份idstring
city_id城市idstring
street_address街道详细地址string
order_pricesku结算金额decimal(28,6)
dicount_pricesku折扣金额decimal(28,6)

dws_order_di

  • 处理点:聚合粒度到订单粒度,聚合指标
  • 唯一键:order_id
字段字段含义字段类型
dt日期string
order_id订单idstring
user_id用户idstring
user_name用户昵称string
gender性别tinyint
age年龄int
shop_id店铺idstring
shop_name商铺名称string
industry_id行业idstring
industry_name行业名称string
shop_phone商铺联系电话string
country_id国家idstring
province_id省份idstring
city_id城市idstring
street_address街道详细地址string
order_price订单结算金额decimal(28,6)
dicount_price订单折扣金额decimal(28,6)

如有疑问,可关注公众号私信我猴~


8940211-e6fcb59338c4b69b.png
任乌拉
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值