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

338 阅读3分钟

有不少没涉及过数仓的同学问我一些比较基础的问题,为了更好的理解前面讲到的一些理论,写一个小小的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

模型设计如下:

模型设计

每张表的结构及逻辑如下:
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)

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

-------------------------------------------------------------------------------------------------

更多资源共享,请关注公众号吼~