27-dwd建模.md 7.2 KB

DWD 建模

本数仓 DWD 层(明细层)的字段建模与设计约定。建模方法论(事件 vs 状态拆分、维度建模五步、星型模型)见 20-数仓分层与建模.md §5;命名规则见 21-命名规范.md §3.4;时间语义见 26-时间语义.md

本文档按"业务过程一节"组织,每节包含业务过程定义 / 粒度 / dt 锚点 / 维度退化策略 / 字段表。

1. 通用约定

1.1 框架字段

所有 DWD 表必带 etl_time TIMESTAMP + 分区 dt STRINGSTORED AS ORC

1.2 业务过程拆分

kb/20 §5.5:每个业务过程一张 _apd_d 事件表(不可变事实,只追加)。订单履约的"下单 / 支付 / 发货 / 签收"各拆一张;拼团循环动作(发起 / 审核 / 拒绝 / 重提交)按需各拆一张。

1.3 维度退化策略

DWD 直引 DIM 层已清洗字段,不在 DWD 二次清洗、不做空值兜底。如 cgi.sport 脏数据归一在 dim_trd_card_group_ful_d 完成(见 28-dim建模.md §3.2),DWD pay 维度退化时直引 DIM 已清洗的 sport

1.4 分区与写入

  • 分区锚点:业务时间(事件发生日,如 payment_success_time),不是抽取日
  • 写入策略:默认单分区 dt=T-1,不回算(ODS 漂移已在 ODS 层归位,DWD 不二次兜底)
  • 重跑幂等:INSERT OVERWRITE 单分区

2. dwd_trd_order_pay_apd_d(订单支付明细)

2.1 业务过程

订单支付完成。源表 ods_trd_card_group_order_info_inc_d 中筛选支付成功的订单。

支付成功判定:

WHERE order_type = 'group'
  AND status IN (101, 103, 104, 105, 106, 301, 302)

2.2 粒度

订单 id(一条 card_group_order_info 记录 = 一行)。

2.3 dt 锚点

DATE(payment_success_time),业务时间分区。同一笔订单在 ODS 层(update_time 锚点)和 DWD 层(业务时间锚点)的分区位置不同,是建模设计的预期。

2.4 维度退化

字段来源 退化字段
dim_trd_card_group_ful_d(拼团 → 品类) category / manufacturer / sets / year / list_id / panini_list_id / group_name
card_group_order_info 自有 其他业务字段直存

DWD 不二次清洗 category(dim_trd_card_group_ful_d 已归一脏数据)。不带大类 main_category(业务侧定:拼团大类 lv1 业务库原名 first_sport,1 期不引,2 期再讨论)。

2.5 accounts_payable_cny 派生规则

业务库分/元单位混存,按 point_type 区分换算:

CASE
    WHEN cgoi.point_type LIKE 'mer_act%' THEN ROUND(cgoi.accounts_payable / 100.00, 2)
    ELSE cgoi.accounts_payable
END AS accounts_payable_cny

point_type LIKE 'mer_act%' 时除 100,其他直取。DWD 内置该规则,下游不再处理。GMV 口径走该字段。

2.6 字段表

分组 字段 类型 来源 说明
主键 order_id BIGINT order.id 订单 id
标识 order_no STRING order 订单编码
标识 combination_no STRING order 拆分订单关联编号
标识 give_order_id BIGINT order 赠与关联订单 id
用户维度 user_id BIGINT order
商家维度 merchant_id BIGINT order
拼团维度 group_info_id BIGINT order
拼团维度退化 group_name STRING dim_trd_card_group 拼团名称
拼团维度退化 list_id BIGINT dim_trd_card_group 商家上线 checklist id(业务库快照冗余)
拼团维度退化 panini_list_id BIGINT dim_trd_card_group 帕尼尼 list id(业务库快照冗余)
拼团维度退化 category STRING dim_trd_card_group 品类(lv2,DIM 已清洗,权威源)
拼团维度退化 manufacturer STRING dim_trd_card_group 厂商
拼团维度退化 sets STRING dim_trd_card_group 系列
拼团维度退化 year STRING dim_trd_card_group 年份(赛季)
收货 shipping_address_id BIGINT order
数量 purchase_count BIGINT order 购买份数
数量 give_num BIGINT order 赠送个数
金额 accounts_payable_cny DECIMAL(20,4) 派生(见 §2.5) GMV 字段
金额 actual_payment_cny DECIMAL(20,4) order.actual_payment 实付款(GMV 不用此字段,保留作冗余)
金额 trade_amount_cny DECIMAL(20,4) order 订单交易金额
金额 settlement_amount_cny DECIMAL(20,4) order 结算金额(实付-退款)
金额 card_price_cny DECIMAL(20,4) order 应付款(拼团时点价)
金额 act_price_cny DECIMAL(20,4) order 应付款(活动价)
金额 discount_cny DECIMAL(20,4) order 折扣
金额 discount_amount_cny DECIMAL(20,4) order 折扣金额
金额 platform_discount_cny DECIMAL(20,4) order 平台券折扣
金额 member_discount_cny DECIMAL(20,4) order 会员折扣
金额 act_discount_cny DECIMAL(20,4) order 活动折扣
金额 point_deduct_cny DECIMAL(20,4) order 积分抵扣金额
金额 shipping_cost_cny DECIMAL(20,4) order 运费
金额 shipping_free_amount_cny DECIMAL(20,4) order 运费券金额
积分 point BIGINT order 消耗积分
积分 discount_point BIGINT order 折扣积分
优惠券 coupon BIGINT order 优惠券 id
优惠券 platform_coupon BIGINT order 平台券 id
优惠券 shipping_free_id BIGINT order 运费券 id
支付 payment_type STRING order 支付方式-交易类型
支付 payment_sub_type STRING order 支付子分类
支付 payment_status STRING order 交易状态
支付 payment_status_desc STRING order 交易状态描述
支付 payment_time TIMESTAMP order 支付时间
支付 payment_success_time TIMESTAMP order 支付完成时间(dt 锚点)
支付 pay_record TINYINT order 是否重复支付
业务标记 order_type STRING order 订单类型
业务标记 order_sub_type STRING order 订单子类型(含赠与)
业务标记 give_user_code STRING order 赠与人
业务标记 status BIGINT order 订单状态
业务标记 serve_status BIGINT order 业务状态
业务标记 refuse_status TINYINT order 是否接受累积发货
业务标记 invoice_id BIGINT order 发票记录 id
业务标记 anonymous BOOLEAN order 是否匿名
业务标记 pick_up_type STRING order 提货方式
业务标记 point_type STRING order 使用积分类型
业务标记 open_self TINYINT order 是否商家代拆
业务标记 goods_allocate TINYINT order 卡密是否分配
风控 waring_type STRING order 风险异常类型
风控 waring_status TINYINT order 风险异常状态
时间 order_create_time TIMESTAMP order.create_time 下单时间
时间 order_update_time TIMESTAMP order.update_time 订单最近更新时间
时间 expire_time TIMESTAMP order 过期时间
软删 is_deleted BOOLEAN order 软删归一
框架 etl_time TIMESTAMP 派生 ETL 处理时间
分区 dt STRING DATE(payment_success_time) 业务时间分区