ods_trd_card_group_order_info_init.sql 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. -- 作者:tianyu.chu
  2. -- 日期:2026-05-07
  3. -- 工单:(无)
  4. -- 目的:订单表 ods 初始化一次性灌入:raw_his_o(存量历史)+ raw_inc_d(已跑全部增量)UNION ALL,
  5. -- 按 DATE_FORMAT(update_time, 'yyyyMMdd') 归位到 ods 各 dt 分区,(id, ods_dt) dedupe,动态分区写入
  6. -- 状态:[待执行]
  7. -- 备注:跑一次后由 jobs/ods/trd/ods_trd_card_group_order_info_inc_d.sql 接管日常增量;
  8. -- his_o + inc_d schema 完全一致(91 字段 STRING),SELECT * UNION ALL 安全;
  9. -- update_time 为空的行落入 __HIVE_DEFAULT_PARTITION__(非阻塞,下游自行处理)
  10. INSERT OVERWRITE TABLE ods.ods_trd_card_group_order_info_inc_d PARTITION (dt)
  11. SELECT
  12. CAST(id AS BIGINT) AS id,
  13. CAST(group_info_id AS BIGINT) AS group_info_id,
  14. CAST(merchant_id AS BIGINT) AS merchant_id,
  15. CAST(user_id AS BIGINT) AS user_id,
  16. CAST(shipping_address_id AS BIGINT) AS shipping_address_id,
  17. CAST(purchase_count AS BIGINT) AS purchase_count,
  18. order_no AS order_no,
  19. CAST(accounts_payable AS DECIMAL(20,4)) AS accounts_payable,
  20. CAST(actual_payment AS DECIMAL(20,4)) AS actual_payment,
  21. payment_type AS payment_type,
  22. CAST(payment_time AS TIMESTAMP) AS payment_time,
  23. CAST(coupon AS BIGINT) AS coupon,
  24. CAST(discount AS DECIMAL(20,4)) AS discount,
  25. CAST(status AS BIGINT) AS status,
  26. remark AS remark,
  27. CAST(create_time AS TIMESTAMP) AS create_time,
  28. create_by AS create_by,
  29. CAST(update_time AS TIMESTAMP) AS update_time,
  30. update_by AS update_by,
  31. payment_status AS payment_status,
  32. payment_status_desc AS payment_status_desc,
  33. CAST(payment_success_time AS TIMESTAMP) AS payment_success_time,
  34. CAST(del_flg AS BIGINT) AS del_flg,
  35. curier_company AS curier_company,
  36. CAST(refund_fee AS DECIMAL(20,4)) AS refund_fee,
  37. CAST(refund_time AS TIMESTAMP) AS refund_time,
  38. CAST(anonymous AS BOOLEAN) AS anonymous,
  39. pick_up_type AS pick_up_type,
  40. CAST(ship_time AS TIMESTAMP) AS ship_time,
  41. CAST(refund_success_time AS TIMESTAMP) AS refund_success_time,
  42. refund_recv_accout AS refund_recv_accout,
  43. refund_account AS refund_account,
  44. refund_request_source AS refund_request_source,
  45. CAST(card_price AS DECIMAL(20,4)) AS card_price,
  46. CAST(act_price AS DECIMAL(20,4)) AS act_price,
  47. goods_price_json AS goods_price_json,
  48. payment_sub_type AS payment_sub_type,
  49. team_first AS team_first,
  50. CAST(refuse_status AS BIGINT) AS refuse_status,
  51. prop1 AS prop1,
  52. prop2 AS prop2,
  53. prop3 AS prop3,
  54. CAST(point AS BIGINT) AS point,
  55. order_type AS order_type,
  56. CAST(trade_amount AS DECIMAL(20,4)) AS trade_amount,
  57. refund_type AS refund_type,
  58. refund_reason AS refund_reason,
  59. evaluation AS evaluation,
  60. CAST(user_refund_time AS TIMESTAMP) AS user_refund_time,
  61. CAST(refund_status AS BIGINT) AS refund_status,
  62. merchant_refund_reason AS merchant_refund_reason,
  63. CAST(point_deduct AS DECIMAL(20,4)) AS point_deduct,
  64. CAST(shipping_cost AS DECIMAL(20,4)) AS shipping_cost,
  65. merchant_remark AS merchant_remark,
  66. CAST(pay_record AS BIGINT) AS pay_record,
  67. order_sub_type AS order_sub_type,
  68. give_user_code AS give_user_code,
  69. CAST(give_order_id AS BIGINT) AS give_order_id,
  70. CAST(read_flag AS BIGINT) AS read_flag,
  71. CAST(give_num AS BIGINT) AS give_num,
  72. CAST(invoice_id AS BIGINT) AS invoice_id,
  73. combination_no AS combination_no,
  74. CAST(open_self AS BIGINT) AS open_self,
  75. refund_desc AS refund_desc,
  76. CAST(goods_allocate AS BIGINT) AS goods_allocate,
  77. CAST(close_payment_status AS BIGINT) AS close_payment_status,
  78. CAST(close_payment_time AS TIMESTAMP) AS close_payment_time,
  79. CAST(finished_time AS TIMESTAMP) AS finished_time,
  80. CAST(expire_time AS TIMESTAMP) AS expire_time,
  81. CAST(settlement_amount AS DECIMAL(20,4)) AS settlement_amount,
  82. CAST(platform_coupon AS BIGINT) AS platform_coupon,
  83. CAST(platform_discount AS DECIMAL(20,4)) AS platform_discount,
  84. CAST(discount_amount AS DECIMAL(20,4)) AS discount_amount,
  85. CAST(member_discount AS DECIMAL(20,4)) AS member_discount,
  86. CAST(shipping_free_id AS BIGINT) AS shipping_free_id,
  87. CAST(shipping_free_amount AS DECIMAL(20,4)) AS shipping_free_amount,
  88. CAST(discount_point AS BIGINT) AS discount_point,
  89. CAST(un_shipped_num AS BIGINT) AS un_shipped_num,
  90. CAST(pre_un_shipped_num AS BIGINT) AS pre_un_shipped_num,
  91. CAST(wait_shipped_num AS BIGINT) AS wait_shipped_num,
  92. CAST(pre_wait_shipped_num AS BIGINT) AS pre_wait_shipped_num,
  93. CAST(refuse_time AS TIMESTAMP) AS refuse_time,
  94. CAST(refuse_notice AS BIGINT) AS refuse_notice,
  95. CAST(pickup_time AS TIMESTAMP) AS pickup_time,
  96. waring_type AS waring_type,
  97. CAST(waring_status AS BIGINT) AS waring_status,
  98. point_type AS point_type,
  99. CAST(delivery_end_time AS TIMESTAMP) AS delivery_end_time,
  100. CAST(serve_status AS BIGINT) AS serve_status,
  101. CAST(self_pickup_time AS TIMESTAMP) AS self_pickup_time,
  102. CAST(act_discount AS DECIMAL(20,4)) AS act_discount,
  103. CASE WHEN del_flg = '1' THEN TRUE ELSE FALSE END AS is_deleted,
  104. ods_dt AS dt
  105. FROM (
  106. SELECT *,
  107. DATE_FORMAT(update_time, 'yyyyMMdd') AS ods_dt,
  108. ROW_NUMBER() OVER (
  109. PARTITION BY id, DATE_FORMAT(update_time, 'yyyyMMdd')
  110. ORDER BY update_time DESC
  111. ) AS rn
  112. FROM (
  113. SELECT
  114. id, group_info_id, merchant_id, user_id, shipping_address_id, purchase_count,
  115. order_no, accounts_payable, actual_payment, payment_type, payment_time, coupon,
  116. discount, status, remark, create_time, create_by, update_time, update_by,
  117. payment_status, payment_status_desc, payment_success_time, del_flg, curier_company,
  118. refund_fee, refund_time, anonymous, pick_up_type, ship_time, refund_success_time,
  119. refund_recv_accout, refund_account, refund_request_source, card_price, act_price,
  120. goods_price_json, payment_sub_type, team_first, refuse_status, prop1, prop2, prop3,
  121. point, order_type, trade_amount, refund_type, refund_reason, evaluation,
  122. user_refund_time, refund_status, merchant_refund_reason, point_deduct, shipping_cost,
  123. merchant_remark, pay_record, order_sub_type, give_user_code, give_order_id, read_flag,
  124. give_num, invoice_id, combination_no, open_self, refund_desc, goods_allocate,
  125. close_payment_status, close_payment_time, finished_time, expire_time, settlement_amount,
  126. platform_coupon, platform_discount, discount_amount, member_discount, shipping_free_id,
  127. shipping_free_amount, discount_point, un_shipped_num, pre_un_shipped_num, wait_shipped_num,
  128. pre_wait_shipped_num, refuse_time, refuse_notice, pickup_time, waring_type, waring_status,
  129. point_type, delivery_end_time, serve_status, self_pickup_time, act_discount
  130. FROM raw.raw_trd_card_group_order_info_his_o
  131. UNION ALL
  132. SELECT
  133. id, group_info_id, merchant_id, user_id, shipping_address_id, purchase_count,
  134. order_no, accounts_payable, actual_payment, payment_type, payment_time, coupon,
  135. discount, status, remark, create_time, create_by, update_time, update_by,
  136. payment_status, payment_status_desc, payment_success_time, del_flg, curier_company,
  137. refund_fee, refund_time, anonymous, pick_up_type, ship_time, refund_success_time,
  138. refund_recv_accout, refund_account, refund_request_source, card_price, act_price,
  139. goods_price_json, payment_sub_type, team_first, refuse_status, prop1, prop2, prop3,
  140. point, order_type, trade_amount, refund_type, refund_reason, evaluation,
  141. user_refund_time, refund_status, merchant_refund_reason, point_deduct, shipping_cost,
  142. merchant_remark, pay_record, order_sub_type, give_user_code, give_order_id, read_flag,
  143. give_num, invoice_id, combination_no, open_self, refund_desc, goods_allocate,
  144. close_payment_status, close_payment_time, finished_time, expire_time, settlement_amount,
  145. platform_coupon, platform_discount, discount_amount, member_discount, shipping_free_id,
  146. shipping_free_amount, discount_point, un_shipped_num, pre_un_shipped_num, wait_shipped_num,
  147. pre_wait_shipped_num, refuse_time, refuse_notice, pickup_time, waring_type, waring_status,
  148. point_type, delivery_end_time, serve_status, self_pickup_time, act_discount
  149. FROM raw.raw_trd_card_group_order_info_inc_d
  150. ) u
  151. ) t
  152. WHERE t.rn = 1;