tmp.md 13 KB

为 B/C/D/全链路的每个 _uv 级别添加:

  • rov = 带回UV / 成本曝光数
  • ror = 带回UV / 成本人数

分母 = 该级别的输入来源(上一级的输出),hop 和 depth 都逐级递推。

数据流 & 分母推导

逐级传播逻辑

depth维度 (分享链深度, 逐级递推): 曝光 → share → depth=1点击(b1) → reshare → depth=2点击(b2) → reshare → depth=3点击(b3)

hop维度 (二次传播跳数, 逐级递推): B chain output → [C hop1] → C hop1 output → [C hop2] → C hop2 output → [C hop3]

完整分母映射 ┌─────────────────────┬─────────────────────┬─────────────────────┐ │ 字段 │ rov 分母 (成本曝光) │ ror 分母 (成本人数) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ B链 │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ bn (全量) │ COUNT(1) │ COUNT(DISTINCT mid) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ b1 (depth=1) │ COUNT(1) │ COUNT(DISTINCT mid) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ b2 (depth=2) │ SUM(b1_exp) │ SUM(b1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ b3 (depth=3) │ SUM(b2_exp) │ SUM(b2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ C链全量depth │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ cn_1 (hop1) │ SUM(bn_exp) │ SUM(bn_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ cn_2 (hop2) │ SUM(cn_1_exp) │ SUM(cn_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ cn_3 (hop3) │ SUM(cn_2_exp) │ SUM(cn_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ cn (合计) │ SUM(bn_exp) │ SUM(bn_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ C链depth拆分 (hop1) │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c1_1 (d1-hop1) │ SUM(bn_exp) │ SUM(bn_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c2_1 (d2-hop1) │ SUM(c1_1_exp) │ SUM(c1_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c3_1 (d3-hop1) │ SUM(c2_1_exp) │ SUM(c2_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ C链depth拆分 (hop2) │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c1_2 (d1-hop2) │ SUM(cn_1_exp) │ SUM(cn_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c2_2 (d2-hop2) │ SUM(c1_2_exp) │ SUM(c1_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c3_2 (d3-hop2) │ SUM(c2_2_exp) │ SUM(c2_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ C链depth拆分 (hop3) │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c1_3 (d1-hop3) │ SUM(cn_2_exp) │ SUM(cn_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c2_3 (d2-hop3) │ SUM(c1_3_exp) │ SUM(c1_3_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ c3_3 (d3-hop3) │ SUM(c2_3_exp) │ SUM(c2_3_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ D链全量depth │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ dn_1 (hop1) │ SUM(d0) │ COUNT(DISTINCT mid) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ dn_2 (hop2) │ SUM(dn_1_exp) │ SUM(dn_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ dn_3 (hop3) │ SUM(dn_2_exp) │ SUM(dn_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ dn (合计) │ SUM(d0) │ COUNT(DISTINCT mid) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ D链depth拆分 (hop1) │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d1_1 (d1-hop1) │ SUM(d0) │ COUNT(DISTINCT mid) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d2_1 (d2-hop1) │ SUM(d1_1_exp) │ SUM(d1_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d3_1 (d3-hop1) │ SUM(d2_1_exp) │ SUM(d2_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ D链depth拆分 (hop2) │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d1_2 (d1-hop2) │ SUM(dn_1_exp) │ SUM(dn_1_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d2_2 (d2-hop2) │ SUM(d1_2_exp) │ SUM(d1_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d3_2 (d3-hop2) │ SUM(d2_2_exp) │ SUM(d2_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ D链depth拆分 (hop3) │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d1_3 (d1-hop3) │ SUM(dn_2_exp) │ SUM(dn_2_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d2_3 (d2-hop3) │ SUM(d1_3_exp) │ SUM(d1_3_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ d3_3 (d3-hop3) │ SUM(d2_3_exp) │ SUM(d2_3_uv) │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ 全链路 │ │ │ ├─────────────────────┼─────────────────────┼─────────────────────┤ │ all │ COUNT(1) │ COUNT(DISTINCT mid) │ └─────────────────────┴─────────────────────┴─────────────────────┘ 规则总结:

  • depth 维度: depth=1 的成本=该hop的入口; depth=N+1 的成本=depth=N 的输出
  • hop 维度: hop1 的成本=链路入口; hop N+1 的成本=hop N 全量depth的输出
  • D链 hop1 没有独立的成本人数(d0是同一用户session内曝光), 用 exposure_uv

实施步骤

  1. 输出 CSV 到 table_gen/rov_ror_fields.csv (61 字段的完整清单)
  2. DDL: 在 CREATE TABLE 每个链路块末尾追加 DOUBLE 字段
  3. SELECT: 追加 ROUND(COALESCE(numerator / NULLIF(denominator, 0), 0), 6)
  4. 验证: grep 计数确保 DDL 和 SELECT 字段数一致

文件

  • loghubods.dwd_recsys_alg_exposure_agg_wide_20260209.sql