dim_trd_card_group_ful_d.sql 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. -- 作者:tianyu.chu
  2. -- 日期:2026-05-10
  3. -- 工单:(无)
  4. -- 目的:dim_trd_card_group_ful_d 日常增量(kb/28 §1.3 + ADR-08,业界主流模式 B):
  5. -- (a) today_changed = 今日 ods cgi 增量 group_info_id 集合;
  6. -- (b) today_rebuilt = 今日 ods cgi 行(sport→category 清洗);
  7. -- (c) 昨日 dim 中今日没变的 group_info_id (NOT IN today_changed) 直接保留;
  8. -- (d) UNION ALL 写入 dim dt=${dt} 单分区
  9. -- 状态:[草案]
  10. -- 备注:sched=T,${dt}=T-1,${pdt}=T-2;
  11. -- 单源(ods.cgi 仅一张表)写法比 dim_usr_user 简单:今日变更行直接用今日 cgi 字段,无需 LEFT JOIN 昨日 dim 兜底;
  12. -- sport→category 清洗规则 init 与 sche 同步实现(kb/28 §3.2);
  13. -- 性能:dim 大表只 scan + broadcast NOT IN 剪枝,不参与 shuffle;
  14. -- 前置 DS DEPENDENT:ods.cgi.dt=${dt} + dim.dt=${pdt}
  15. INSERT OVERWRITE TABLE dim.dim_trd_card_group_ful_d PARTITION (dt='${dt}')
  16. WITH today_cgi AS (
  17. SELECT *
  18. FROM (
  19. SELECT *,
  20. ROW_NUMBER() OVER (
  21. PARTITION BY id
  22. ORDER BY COALESCE(update_time, create_time) DESC
  23. ) AS rn
  24. FROM ods.ods_trd_card_group_info_inc_d
  25. WHERE dt = '${dt}'
  26. ) t
  27. WHERE t.rn = 1
  28. ),
  29. today_changed AS (
  30. SELECT id AS group_info_id FROM today_cgi
  31. ),
  32. today_rebuilt AS (
  33. SELECT
  34. cg.id AS group_info_id,
  35. cg.code AS code,
  36. cg.appid AS appid,
  37. cg.name AS name,
  38. cg.display_name AS display_name,
  39. cg.group_show_name AS group_show_name,
  40. cg.merchant_id AS merchant_id,
  41. cg.mer_name AS mer_name,
  42. cg.list_id AS list_id,
  43. cg.list_code AS list_code,
  44. cg.panini_list_id AS panini_list_id,
  45. CASE
  46. WHEN cg.sport = 'mlb' THEN 'MLB'
  47. WHEN cg.sport = 'Boxing' THEN 'UFC'
  48. WHEN cg.sport = 'other' THEN NULL
  49. ELSE cg.sport
  50. END AS category,
  51. cg.year AS year,
  52. cg.manufacturer AS manufacturer,
  53. cg.sets AS sets,
  54. cg.type AS type,
  55. cg.sub_type AS sub_type,
  56. cg.random_type AS random_type,
  57. cg.specs AS specs,
  58. cg.total_price AS total_price_cny,
  59. cg.unit_price AS unit_price_cny,
  60. cg.act_price AS act_price_cny,
  61. cg.copies AS copies,
  62. cg.total_num AS total_num,
  63. cg.weight AS weight,
  64. cg.order_quota_min AS order_quota_min,
  65. cg.order_quota_max AS order_quota_max,
  66. cg.user_quota_max AS user_quota_max,
  67. cg.min_card_num AS min_card_num,
  68. cg.mix_copies AS mix_copies,
  69. cg.change_type AS change_type,
  70. cg.status AS status,
  71. cg.sold_copies AS sold_copies,
  72. cg.real_sold_num AS real_sold_num,
  73. cg.sold_end_time AS sold_end_time,
  74. cg.finished_time AS finished_time,
  75. cg.release_time AS release_time,
  76. cg.start_time AS start_time,
  77. cg.cycle AS cycle,
  78. cg.group_full_time AS group_full_time,
  79. cg.review_hold_time AS review_hold_time,
  80. cg.review_approval_time AS review_approval_time,
  81. cg.review_num AS review_num,
  82. cg.confirm_send_time AS confirm_send_time,
  83. cg.close_payment_time AS close_payment_time,
  84. cg.close_payment_status AS close_payment_status,
  85. cg.group_sets_no AS group_sets_no,
  86. cg.live_create_time AS live_create_time,
  87. cg.live_start_time AS live_start_time,
  88. cg.live_end_time AS live_end_time,
  89. cg.report_start_time AS report_start_time,
  90. cg.report_end_time AS report_end_time,
  91. cg.report_review_num AS report_review_num,
  92. cg.report_review_first_time AS report_review_first_time,
  93. cg.report_review_end_time AS report_review_end_time,
  94. cg.act_id AS act_id,
  95. cg.act_type AS act_type,
  96. cg.act_point_type AS act_point_type,
  97. cg.free_flag AS free_flag,
  98. cg.exclusive AS exclusive,
  99. cg.has_bg AS has_bg,
  100. cg.team_first AS team_first,
  101. cg.use_member_discount AS use_member_discount,
  102. cg.use_coupon AS use_coupon,
  103. cg.user_level AS user_level,
  104. cg.merchant_open AS merchant_open,
  105. cg.merchant_sort AS merchant_sort,
  106. cg.custom AS custom,
  107. cg.gift_card_id AS gift_card_id,
  108. cg.open_card AS open_card,
  109. cg.goods_type AS goods_type,
  110. cg.point_rate AS point_rate,
  111. cg.point_max AS point_max,
  112. cg.point_min AS point_min,
  113. cg.point_type AS point_type,
  114. cg.payment_method AS payment_method,
  115. cg.payment_total_price AS payment_total_price_cny,
  116. cg.payment_commission AS payment_commission_cny,
  117. cg.payment_finished_price AS payment_finished_price_cny,
  118. cg.payment_remain_price AS payment_remain_price_cny,
  119. cg.payment_online_price AS payment_online_price_cny,
  120. cg.commission_rate AS commission_rate,
  121. cg.hot_type AS hot_type,
  122. cg.report_flag AS report_flag,
  123. cg.banner_end_time AS banner_end_time,
  124. cg.waring_type AS waring_type,
  125. cg.compensation_status AS compensation_status,
  126. cg.reviewmsg AS reviewmsg,
  127. cg.review_account AS review_account,
  128. cg.`lock` AS `lock`,
  129. cg.marketing_info AS marketing_info,
  130. cg.msg AS msg,
  131. cg.title AS title,
  132. cg.remark AS remark,
  133. cg.create_time AS create_time,
  134. cg.update_time AS last_update_time,
  135. cg.del_time AS del_time,
  136. cg.is_deleted AS is_deleted,
  137. CURRENT_TIMESTAMP() AS etl_time
  138. FROM today_cgi cg
  139. )
  140. SELECT
  141. group_info_id,
  142. code,
  143. appid,
  144. name,
  145. display_name,
  146. group_show_name,
  147. merchant_id,
  148. mer_name,
  149. list_id,
  150. list_code,
  151. panini_list_id,
  152. category,
  153. year,
  154. manufacturer,
  155. sets,
  156. type,
  157. sub_type,
  158. random_type,
  159. specs,
  160. total_price_cny,
  161. unit_price_cny,
  162. act_price_cny,
  163. copies,
  164. total_num,
  165. weight,
  166. order_quota_min,
  167. order_quota_max,
  168. user_quota_max,
  169. min_card_num,
  170. mix_copies,
  171. change_type,
  172. status,
  173. sold_copies,
  174. real_sold_num,
  175. sold_end_time,
  176. finished_time,
  177. release_time,
  178. start_time,
  179. cycle,
  180. group_full_time,
  181. review_hold_time,
  182. review_approval_time,
  183. review_num,
  184. confirm_send_time,
  185. close_payment_time,
  186. close_payment_status,
  187. group_sets_no,
  188. live_create_time,
  189. live_start_time,
  190. live_end_time,
  191. report_start_time,
  192. report_end_time,
  193. report_review_num,
  194. report_review_first_time,
  195. report_review_end_time,
  196. act_id,
  197. act_type,
  198. act_point_type,
  199. free_flag,
  200. exclusive,
  201. has_bg,
  202. team_first,
  203. use_member_discount,
  204. use_coupon,
  205. user_level,
  206. merchant_open,
  207. merchant_sort,
  208. custom,
  209. gift_card_id,
  210. open_card,
  211. goods_type,
  212. point_rate,
  213. point_max,
  214. point_min,
  215. point_type,
  216. payment_method,
  217. payment_total_price_cny,
  218. payment_commission_cny,
  219. payment_finished_price_cny,
  220. payment_remain_price_cny,
  221. payment_online_price_cny,
  222. commission_rate,
  223. hot_type,
  224. report_flag,
  225. banner_end_time,
  226. waring_type,
  227. compensation_status,
  228. reviewmsg,
  229. review_account,
  230. `lock`,
  231. marketing_info,
  232. msg,
  233. title,
  234. remark,
  235. create_time,
  236. last_update_time,
  237. del_time,
  238. is_deleted,
  239. etl_time
  240. FROM today_rebuilt
  241. UNION ALL
  242. SELECT
  243. group_info_id,
  244. code,
  245. appid,
  246. name,
  247. display_name,
  248. group_show_name,
  249. merchant_id,
  250. mer_name,
  251. list_id,
  252. list_code,
  253. panini_list_id,
  254. category,
  255. year,
  256. manufacturer,
  257. sets,
  258. type,
  259. sub_type,
  260. random_type,
  261. specs,
  262. total_price_cny,
  263. unit_price_cny,
  264. act_price_cny,
  265. copies,
  266. total_num,
  267. weight,
  268. order_quota_min,
  269. order_quota_max,
  270. user_quota_max,
  271. min_card_num,
  272. mix_copies,
  273. change_type,
  274. status,
  275. sold_copies,
  276. real_sold_num,
  277. sold_end_time,
  278. finished_time,
  279. release_time,
  280. start_time,
  281. cycle,
  282. group_full_time,
  283. review_hold_time,
  284. review_approval_time,
  285. review_num,
  286. confirm_send_time,
  287. close_payment_time,
  288. close_payment_status,
  289. group_sets_no,
  290. live_create_time,
  291. live_start_time,
  292. live_end_time,
  293. report_start_time,
  294. report_end_time,
  295. report_review_num,
  296. report_review_first_time,
  297. report_review_end_time,
  298. act_id,
  299. act_type,
  300. act_point_type,
  301. free_flag,
  302. exclusive,
  303. has_bg,
  304. team_first,
  305. use_member_discount,
  306. use_coupon,
  307. user_level,
  308. merchant_open,
  309. merchant_sort,
  310. custom,
  311. gift_card_id,
  312. open_card,
  313. goods_type,
  314. point_rate,
  315. point_max,
  316. point_min,
  317. point_type,
  318. payment_method,
  319. payment_total_price_cny,
  320. payment_commission_cny,
  321. payment_finished_price_cny,
  322. payment_remain_price_cny,
  323. payment_online_price_cny,
  324. commission_rate,
  325. hot_type,
  326. report_flag,
  327. banner_end_time,
  328. waring_type,
  329. compensation_status,
  330. reviewmsg,
  331. review_account,
  332. `lock`,
  333. marketing_info,
  334. msg,
  335. title,
  336. remark,
  337. create_time,
  338. last_update_time,
  339. del_time,
  340. is_deleted,
  341. etl_time
  342. FROM dim.dim_trd_card_group_ful_d
  343. WHERE dt = '${pdt}'
  344. AND group_info_id NOT IN (SELECT group_info_id FROM today_changed);