Просмотр исходного кода

docs(table_gen): base/agg_wide 补充头部认知注释

- base: 版本历史、数据源、数据流图、CTE 管线、去环策略
- agg_wide: 依赖链、指标分区总览、rov/ror 分母推导表

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
yangxiaohui 3 недель назад
Родитель
Сommit
bfd273ab51

+ 36 - 1
table_gen/loghubods.dwd_recsys_alg_exposure_agg_wide_20260209.sql

@@ -1,8 +1,43 @@
 -- =====================================================================
--- 曝光回流链路 CUBE 聚合表 (基于 wide 宽表, 增加用户/品类维度 + 模型预估指标)
+-- 曝光回流链路 CUBE 聚合表 (宽表版, 含用户/品类维度 + 模型预估 + 全链路漏斗)
 -- 维度: user_type × hh_bucket × head_merge_leve2 × vid_merge_leve2 × vid_id (CUBE)
+-- 依赖: base_20260209 → (JOIN user_type + video_merge_tag + t_score) → CUBE 聚合
 -- 参考: de.sql + dwd_recsys_alg_exposure_agg_20260209
 -- =====================================================================
+--
+-- 指标分区:
+--   基础流量       exposure_cnt / exposure_uv / vid_cnt / exposure_per_user
+--   分享&回流漏斗  share_exposure_cnt → share_cnt → return_exposure_cnt → return_uv
+--                  + 4 个 rate (share_rate / return_rate / return_rate_noself / share_return_rate)
+--   模型预估       STR (曝光→非自身回流概率) / ROSN (条件回流UV) / ROVN (STR×ROSN)
+--                  每组: _real(label) + _pred(预估) + _copc + _mae + _var
+--                  _real 与漏斗字段等价: str_real=return_rate_noself, rovn_real=return_uv_noself/exposure_cnt
+--   B/C/D 链       每级: _uv + _pv + _exp + _ror + _rov
+--   全链路         all_return_n_uv = B + C + D
+--
+-- rov/ror 分母推导 (逐级递推):
+--   depth 维度: depth=1 的成本=该hop入口; depth=N+1 的成本=depth=N 的输出
+--   hop 维度:   hop1 的成本=链路入口; hop N+1 的成本=hop N 全量depth的输出
+--
+--   B链:  bn/b1 → rov=uv/COUNT(1), ror=uv/COUNT(DISTINCT mid)
+--         b2    → rov=uv/b1_exp,    ror=uv/b1_uv
+--         b3    → rov=uv/b2_exp,    ror=uv/b2_uv
+--   C链全量: cn_1 → rov=uv/bn_exp,    ror=uv/bn_uv
+--            cn_2 → rov=uv/cn_1_exp,  ror=uv/cn_1_uv
+--            cn_3 → rov=uv/cn_2_exp,  ror=uv/cn_2_uv
+--   C链depth拆分: cX_Y → rov=uv/上级exp, ror=uv/上级uv (X=depth, Y=hop)
+--            hop1: c1_1→bn, c2_1→c1_1, c3_1→c2_1
+--            hop2: c1_2→cn_1, c2_2→c1_2, c3_2→c2_2
+--            hop3: c1_3→cn_2, c2_3→c1_3, c3_3→c2_3
+--   D链全量: dn_1 → rov=uv/d0,         ror=uv/COUNT(DISTINCT mid)
+--            dn_2 → rov=uv/dn_1_exp,   ror=uv/dn_1_uv
+--            dn_3 → rov=uv/dn_2_exp,   ror=uv/dn_2_uv
+--   D链depth拆分: dX_Y (同 C 链模式)
+--            hop1: d1_1→d0/mid, d2_1→d1_1, d3_1→d2_1
+--            hop2: d1_2→dn_1, d2_2→d1_2, d3_2→d2_2
+--            hop3: d1_3→dn_2, d2_3→d1_3, d3_3→d2_3
+--   全链路: all → rov=uv/COUNT(1), ror=uv/COUNT(DISTINCT mid)
+-- =====================================================================
 
 -- DROP TABLE IF EXISTS loghubods.dwd_recsys_alg_exposure_agg_wide_20260209;
 CREATE TABLE IF NOT EXISTS loghubods.dwd_recsys_alg_exposure_agg_wide_20260209 (

+ 48 - 4
table_gen/loghubods.dwd_recsys_alg_exposure_base_20260209.sql

@@ -1,9 +1,53 @@
 --@exclude_input=loghubods.video_action_log_flow_new
 --@exclude_input=loghubods.user_share_log_flow
---*********************
--- alg_recsys_rank_labelmatch_20260209
--- 在 20260206 基础上重构 B/C/D 链: sharedepth 维度 + exp/pv/uv/mids 四指标
---*********************
+-- =====================================================================
+-- 曝光回流基础表 (行级, 每行 = 一次曝光)
+-- 版本: 20260209 (基于 20260206 重构 B/C/D 链: +sharedepth 维度 + exp/pv/uv/mids)
+-- 版本历史: 20250108 → 20260206(+B/C/D) → 20260209(+sharedepth+exp/pv/uv/mids)
+-- =====================================================================
+--
+-- 数据源 (3 张流水表):
+--   video_action_log_flow_new  → 曝光事件 (businesstype=videoView)
+--   user_share_log_flow        → 分享事件 (topic=share) + 回流点击 (topic=click)
+--   changwen_rootsourceid_group_hour → rootsourceid 分组名映射
+--
+-- 数据流:
+--   曝光去重 ──→ 分享关联曝光 ──→ 回流关联分享 ──→ B链(直达回流)
+--      │              │                                  │
+--      │              └── 回流关联曝光 ─── 1度/n度回流     ├─→ C链(二次传播, BFS 3hop)
+--      │                                                 └─→ D链(session内后续曝光传播, BFS 3hop)
+--      └── 最终 LEFT JOIN 组装 → 输出行级明细
+--
+-- CTE 管线:
+--   t_return               回流点击去重 (user_share_log_flow topic=click, ROW_NUMBER dedup)
+--   t_share_from_sharelog   分享行为去重 (user_share_log_flow topic=share)
+--   t_exposure_raw/t_exposure  曝光去重 (video_action_log_flow_new, 分 share/非share 两路 UNION ALL)
+--   t_return_exposure_1~4  回流关联曝光: 4 轮渐进放宽 JOIN 条件
+--                          1) subsessionid + headvideoid
+--                          2) sessionid + headvideoid
+--                          3) subsessionid (不限vid)
+--                          4) sessionid (不限vid)
+--   t_normal_share_exposure_1~6  常规分享关联曝光: 6 轮渐进放宽
+--                          1) subsessionid + pagesource + vid, ts>=
+--                          2) sessionid + pagesource + vid, ts>=
+--                          3) subsessionid + pagesource + vid (无ts)
+--                          4) sessionid + pagesource + vid (无ts)
+--                          5) subsessionid + vid
+--                          6) sessionid + vid
+--   t_no_normal_share_exposure_1~4  非常规(detail页)分享关联曝光: 4 轮
+--   t_share_return          bridge: 分享曝光 × 回流点击 (rootshareid + vid + apptype)
+--   B 链  t_exposure_bn (pv/uv/mids) + t_b_exp (exp), 按 sharedepth 拆分
+--   C 链  BFS 3hop: frontier_N → t_c_hopN (pv/uv/mids) + t_c_hopN_exp (exp)
+--   D 链  BFS 3hop: t_d0(成本) → t_d_hopN + t_d_hopN_exp, frontier anti-join 去环
+--   t_share_with_label/_group  分享标签聚合 (1度/n度 pv/uv/mids)
+--   t_exposure_share_return    最终 SELECT: LEFT JOIN 组装所有字段
+--
+-- 关键设计决策:
+--   去环策略: 仅 session 级 anti-join (frontier_N LEFT JOIN 排除已访问 subsessionid)
+--            不做用户级去环 (会丢失 A→B→A→C 中的 C)
+--   sharedepth: 来自 user_share_log_flow 的 click topic, CAST(sharedepth AS BIGINT)
+--   COLLECT_SET + CASE WHEN: 条件不满足时会加入 NULL, SIZE 需要 COALESCE 兜底
+-- =====================================================================
 -- drop table if exists loghubods.dwd_recsys_alg_exposure_base_20260209;
 CREATE TABLE IF NOT EXISTS loghubods.dwd_recsys_alg_exposure_base_20260209
 (