20260715_ods_trd_card_group_info_2026rebucket.sql 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. -- 作者:tianyu.chu
  2. -- 日期:2026-07-15
  3. -- 工单:(无)
  4. -- 目的:一次性重分桶——读中转表 raw.tmp_trd_card_group_info(dt=20260716) 全量 2026 拼团,
  5. -- 按 ods_dt = COALESCE(update_time,create_time) 的日动态分区写入 ods
  6. -- 状态:[待执行]
  7. -- 备注:动态分区 INSERT OVERWRITE 只覆盖 SELECT 出现的 ods_dt(2026 各日),不动 2026 前历史分区;
  8. -- DISTRIBUTE BY dt(=投影后的 ods_dt)防每分区小文件(ADR-15);
  9. -- 不做 (id,ods_dt) 去重——dump 是 PG 单次快照、一单一行、无同日重复,去重空操作。
  10. -- 中间态按决策丢弃:每单只落当前最终态到其最后变更日分区。
  11. -- 跑完确认无误后 DROP TABLE raw.tmp_trd_card_group_info(内部表连数据一起清)。
  12. SET hive.exec.dynamic.partition=true;
  13. SET hive.exec.dynamic.partition.mode=nonstrict;
  14. SET hive.exec.max.dynamic.partitions=2000;
  15. SET hive.exec.max.dynamic.partitions.pernode=2000;
  16. INSERT OVERWRITE TABLE ods.ods_trd_card_group_info_inc_d PARTITION (dt)
  17. SELECT
  18. CAST(id AS BIGINT) AS id,
  19. CAST(merchant_id AS BIGINT) AS merchant_id,
  20. appid AS appid,
  21. name AS name,
  22. code AS code,
  23. CAST(status AS BIGINT) AS status,
  24. specs AS specs,
  25. type AS type,
  26. random_type AS random_type,
  27. CAST(total_price AS DECIMAL(20,4)) AS total_price,
  28. CAST(copies AS BIGINT) AS copies,
  29. CAST(unit_price AS DECIMAL(20,4)) AS unit_price,
  30. CAST(sold_copies AS BIGINT) AS sold_copies,
  31. release_time AS release_time,
  32. cycle AS cycle,
  33. show_applet AS show_applet,
  34. title AS title,
  35. msg AS msg,
  36. remark AS remark,
  37. CAST(create_time AS TIMESTAMP) AS create_time,
  38. update_by AS update_by,
  39. CAST(update_time AS TIMESTAMP) AS update_time,
  40. CAST(order_quota_min AS BIGINT) AS order_quota_min,
  41. CAST(order_quota_max AS BIGINT) AS order_quota_max,
  42. CAST(user_quota_max AS BIGINT) AS user_quota_max,
  43. CAST(start_time AS TIMESTAMP) AS start_time,
  44. marketing_info AS marketing_info,
  45. reviewmsg AS reviewmsg,
  46. CAST(`lock` AS BOOLEAN) AS `lock`,
  47. commission_rate AS commission_rate,
  48. year AS year,
  49. sport AS sport,
  50. manufacturer AS manufacturer,
  51. sets AS sets,
  52. act AS act,
  53. config AS config,
  54. info_config AS info_config,
  55. CAST(total_num AS BIGINT) AS total_num,
  56. CAST(banner_end_time AS TIMESTAMP) AS banner_end_time,
  57. add_banner AS add_banner,
  58. CAST(finished_time AS TIMESTAMP) AS finished_time,
  59. display_name AS display_name,
  60. CAST(group_sets_no AS BIGINT) AS group_sets_no,
  61. CAST(close_payment_time AS TIMESTAMP) AS close_payment_time,
  62. CAST(confirm_send_time AS TIMESTAMP) AS confirm_send_time,
  63. CAST(close_payment_status AS BIGINT) AS close_payment_status,
  64. CAST(open_card AS BIGINT) AS open_card,
  65. close_payment_record AS close_payment_record,
  66. CAST(group_full_time AS TIMESTAMP) AS group_full_time,
  67. CAST(live_create_time AS TIMESTAMP) AS live_create_time,
  68. CAST(live_start_time AS TIMESTAMP) AS live_start_time,
  69. CAST(live_end_time AS TIMESTAMP) AS live_end_time,
  70. CAST(report_start_time AS TIMESTAMP) AS report_start_time,
  71. CAST(report_end_time AS TIMESTAMP) AS report_end_time,
  72. CAST(report_review_num AS BIGINT) AS report_review_num,
  73. CAST(report_review_first_time AS TIMESTAMP) AS report_review_first_time,
  74. CAST(report_review_end_time AS TIMESTAMP) AS report_review_end_time,
  75. CAST(review_hold_time AS TIMESTAMP) AS review_hold_time,
  76. CAST(review_approval_time AS TIMESTAMP) AS review_approval_time,
  77. CAST(review_num AS BIGINT) AS review_num,
  78. config_json AS config_json,
  79. CAST(free_flag AS BIGINT) AS free_flag,
  80. mer_name AS mer_name,
  81. change_type AS change_type,
  82. CAST(act_price AS DECIMAL(20,4)) AS act_price,
  83. act_config_json AS act_config_json,
  84. CAST(real_sold_num AS BIGINT) AS real_sold_num,
  85. CAST(weight AS BIGINT) AS weight,
  86. hot_type AS hot_type,
  87. CAST(team_first AS BIGINT) AS team_first,
  88. prop1 AS prop1,
  89. prop2 AS prop2,
  90. prop3 AS prop3,
  91. CAST(point_rate AS BIGINT) AS point_rate,
  92. CAST(point_max AS BIGINT) AS point_max,
  93. CAST(point_min AS BIGINT) AS point_min,
  94. CAST(list_id AS BIGINT) AS list_id,
  95. list_code AS list_code,
  96. CAST(mix_copies AS BIGINT) AS mix_copies,
  97. sub_type AS sub_type,
  98. act_point_type AS act_point_type,
  99. CAST(payment_method AS BIGINT) AS payment_method,
  100. CAST(payment_total_price AS DECIMAL(20,4)) AS payment_total_price,
  101. CAST(payment_commission AS DECIMAL(20,4)) AS payment_commission,
  102. CAST(payment_finished_price AS DECIMAL(20,4)) AS payment_finished_price,
  103. CAST(payment_remain_price AS DECIMAL(20,4)) AS payment_remain_price,
  104. CAST(payment_online_price AS DECIMAL(20,4)) AS payment_online_price,
  105. CAST(exclusive AS BIGINT) AS exclusive,
  106. CAST(has_bg AS BIGINT) AS has_bg,
  107. CAST(merchant_sort AS BIGINT) AS merchant_sort,
  108. CAST(del_flg AS BIGINT) AS del_flg,
  109. CAST(del_time AS TIMESTAMP) AS del_time,
  110. review_account AS review_account,
  111. CAST(act_id AS BIGINT) AS act_id,
  112. CAST(sold_end_time AS TIMESTAMP) AS sold_end_time,
  113. CAST(panini_list_id AS BIGINT) AS panini_list_id,
  114. hot_type_config AS hot_type_config,
  115. CAST(goods_type AS BIGINT) AS goods_type,
  116. CAST(report_flag AS BIGINT) AS report_flag,
  117. CAST(use_coupon AS BIGINT) AS use_coupon,
  118. CAST(user_level AS BIGINT) AS user_level,
  119. CAST(custom AS BIGINT) AS custom,
  120. CAST(gift_card_id AS BIGINT) AS gift_card_id,
  121. group_show_name AS group_show_name,
  122. CAST(min_card_num AS BIGINT) AS min_card_num,
  123. act_type AS act_type,
  124. waring_type AS waring_type,
  125. CAST(compensation_status AS BIGINT) AS compensation_status,
  126. point_type AS point_type,
  127. first_act_config AS first_act_config,
  128. gift_config AS gift_config,
  129. CAST(version AS BIGINT) AS version,
  130. extra_prop AS extra_prop,
  131. CAST(use_member_discount AS BIGINT) AS use_member_discount,
  132. CAST(merchant_open AS BIGINT) AS merchant_open,
  133. CASE WHEN del_flg = '1' THEN TRUE ELSE FALSE END AS is_deleted,
  134. ods_dt AS dt
  135. FROM (
  136. SELECT *,
  137. DATE_FORMAT(COALESCE(NULLIF(update_time, ''), create_time), 'yyyyMMdd') AS ods_dt
  138. FROM raw.tmp_trd_card_group_info
  139. WHERE dt = '20260716'
  140. ) t
  141. DISTRIBUTE BY dt;