ods_trd_card_group_info_ful_d.sql 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- 作者:tianyu.chu
  2. -- 日期:2026-07-17
  3. -- 工单:(无)
  4. -- 目的:拼团全量最新态日常 merge —— full dt=${dt} ← full dt=${pdt} ⨝ inc dt=${dt},按 id 取最新一版
  5. -- 状态:[草案]
  6. -- 备注:sched=T,${dt}=业务日 T-1、${pdt}=T-2(即前一天的 full)。
  7. -- **静态分区写入**(PARTITION(dt='${dt}'))是硬要求:本 SQL 读 full dt=${pdt} 又写 full,
  8. -- 若用动态分区(PARTITION(dt)),输出路径=表根目录、与读的分区路径重叠,Spark 会报
  9. -- "Cannot overwrite a path that is also being read from"。静态分区的输出是具体分区目录,不重叠。
  10. -- 起点由 manual/backfill/20260717_..._ful_d_seed.sql 一次性 seed;断链需重新 seed。
  11. -- 历史多版本在 inc 表(拉链底座),本表只保当前态。lock 是保留字,SELECT 里必须带反引号。
  12. -- **分区保留 7 天**:本 SQL 不做 drop(Spark SQL 对 DROP PARTITION 比较式过滤支持存疑),
  13. -- 由 DS 后置任务用 Hive 执行:
  14. -- ALTER TABLE ods.ods_trd_card_group_info_ful_d DROP IF EXISTS PARTITION (dt < '$[yyyyMMdd-8]');
  15. INSERT OVERWRITE TABLE ods.ods_trd_card_group_info_ful_d PARTITION (dt='${dt}')
  16. SELECT
  17. id, merchant_id, appid, name, code,
  18. status, specs, type, random_type, total_price,
  19. copies, unit_price, sold_copies, release_time, cycle,
  20. show_applet, title, msg, remark, create_time,
  21. update_by, update_time, order_quota_min, order_quota_max, user_quota_max,
  22. start_time, marketing_info, reviewmsg, `lock`, commission_rate,
  23. year, sport, manufacturer, sets, act,
  24. config, info_config, total_num, banner_end_time, add_banner,
  25. finished_time, display_name, group_sets_no, close_payment_time, confirm_send_time,
  26. close_payment_status, open_card, close_payment_record, group_full_time, live_create_time,
  27. live_start_time, live_end_time, report_start_time, report_end_time, report_review_num,
  28. report_review_first_time, report_review_end_time, review_hold_time, review_approval_time, review_num,
  29. config_json, free_flag, mer_name, change_type, act_price,
  30. act_config_json, real_sold_num, weight, hot_type, team_first,
  31. prop1, prop2, prop3, point_rate, point_max,
  32. point_min, list_id, list_code, mix_copies, sub_type,
  33. act_point_type, payment_method, payment_total_price, payment_commission, payment_finished_price,
  34. payment_remain_price, payment_online_price, exclusive, has_bg, merchant_sort,
  35. del_flg, del_time, review_account, act_id, sold_end_time,
  36. panini_list_id, hot_type_config, goods_type, report_flag, use_coupon,
  37. user_level, custom, gift_card_id, group_show_name, min_card_num,
  38. act_type, waring_type, compensation_status, point_type, first_act_config,
  39. gift_config, version, extra_prop, use_member_discount, merchant_open,
  40. is_deleted
  41. FROM (
  42. SELECT *,
  43. ROW_NUMBER() OVER (PARTITION BY id ORDER BY COALESCE(update_time, create_time) DESC) AS rn
  44. FROM (
  45. SELECT * FROM ods.ods_trd_card_group_info_ful_d WHERE dt = '${pdt}'
  46. UNION ALL
  47. SELECT * FROM ods.ods_trd_card_group_info_inc_d WHERE dt = '${dt}'
  48. ) u
  49. ) t
  50. WHERE t.rn = 1;