Преглед изворни кода

feat(manual/trd): 订单 716+ 大范围 dump→ODS 补数,活动日重灌封顶 0719

新增 tmp dump ini(COALESCE≥0716 当前态全量)+ rebucket SQL(按活动日
explode 创建日∪变更日,OVERWRITE ods 0716~0719),修复按日 re-pull 弄残的分区。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tianyu.chu пре 2 недеља
родитељ
комит
59dcaf56ec

+ 126 - 0
manual/backfill/20260721_ods_trd_card_group_order_info_backfill_rebucket.sql

@@ -0,0 +1,126 @@
+-- 作者:tianyu.chu
+-- 日期:2026-07-21
+-- 工单:(无)
+-- 目的:一次性补数重灌——读中转表 raw.tmp_trd_card_group_order_info(dt=20260721) 当前态全量,
+--       每单按「活动日」展开:创建日 + 变更日(COALESCE),OVERWRITE 写入 ods 的 0716~0719 分区,
+--       修复此前按日 re-pull 弄残的这几天(补回被 COALESCE 甩掉的 create 日 presence)。
+-- 状态:[待执行]
+-- 备注:与日常 ods_trd_card_group_order_info_inc_d.sql 同口径(dt=活动日=创建日∪变更日);
+--       分区封顶 0719——0720 交给今天的日调度自愈,别在这抢写;
+--       explode 用 CASE 去重「创建日=变更日」的单;tmp 为 PG 单次快照、一单一行,(id,act_dt) 天然不重;
+--       动态分区 OVERWRITE 只覆盖 SELECT 出现的 0716~0719,不动历史与 0720+(本环境默认 DYNAMIC);
+--       DISTRIBUTE BY act_dt 防每分区小文件(ADR-15);
+--       跑完并核对无误后 DROP TABLE raw.tmp_trd_card_group_order_info(内部表连数据一起清)。
+
+SET hive.exec.dynamic.partition=true;
+SET hive.exec.dynamic.partition.mode=nonstrict;
+SET hive.exec.max.dynamic.partitions=2000;
+SET hive.exec.max.dynamic.partitions.pernode=2000;
+
+INSERT OVERWRITE TABLE ods.ods_trd_card_group_order_info_inc_d PARTITION (dt)
+SELECT
+    CAST(id                        AS BIGINT)        AS id,
+    CAST(group_info_id             AS BIGINT)        AS group_info_id,
+    CAST(merchant_id               AS BIGINT)        AS merchant_id,
+    CAST(user_id                   AS BIGINT)        AS user_id,
+    CAST(shipping_address_id       AS BIGINT)        AS shipping_address_id,
+    CAST(purchase_count            AS BIGINT)        AS purchase_count,
+    order_no                                         AS order_no,
+    CAST(accounts_payable          AS DECIMAL(20,4)) AS accounts_payable,
+    CAST(actual_payment            AS DECIMAL(20,4)) AS actual_payment,
+    payment_type                                     AS payment_type,
+    CAST(payment_time              AS TIMESTAMP)     AS payment_time,
+    CAST(coupon                    AS BIGINT)        AS coupon,
+    CAST(discount                  AS DECIMAL(20,4)) AS discount,
+    CAST(status                    AS BIGINT)        AS status,
+    remark                                           AS remark,
+    CAST(create_time               AS TIMESTAMP)     AS create_time,
+    create_by                                        AS create_by,
+    CAST(update_time               AS TIMESTAMP)     AS update_time,
+    update_by                                        AS update_by,
+    payment_status                                   AS payment_status,
+    payment_status_desc                              AS payment_status_desc,
+    CAST(payment_success_time      AS TIMESTAMP)     AS payment_success_time,
+    CAST(del_flg                   AS BIGINT)        AS del_flg,
+    curier_company                                   AS curier_company,
+    CAST(refund_fee                AS DECIMAL(20,4)) AS refund_fee,
+    CAST(refund_time               AS TIMESTAMP)     AS refund_time,
+    CAST(anonymous                 AS BOOLEAN)       AS anonymous,
+    pick_up_type                                     AS pick_up_type,
+    CAST(ship_time                 AS TIMESTAMP)     AS ship_time,
+    CAST(refund_success_time       AS TIMESTAMP)     AS refund_success_time,
+    refund_recv_accout                               AS refund_recv_accout,
+    refund_account                                   AS refund_account,
+    refund_request_source                            AS refund_request_source,
+    CAST(card_price                AS DECIMAL(20,4)) AS card_price,
+    CAST(act_price                 AS DECIMAL(20,4)) AS act_price,
+    goods_price_json                                 AS goods_price_json,
+    payment_sub_type                                 AS payment_sub_type,
+    team_first                                       AS team_first,
+    CAST(refuse_status             AS BIGINT)        AS refuse_status,
+    prop1                                            AS prop1,
+    prop2                                            AS prop2,
+    prop3                                            AS prop3,
+    CAST(point                     AS BIGINT)        AS point,
+    order_type                                       AS order_type,
+    CAST(trade_amount              AS DECIMAL(20,4)) AS trade_amount,
+    refund_type                                      AS refund_type,
+    refund_reason                                    AS refund_reason,
+    evaluation                                       AS evaluation,
+    CAST(user_refund_time          AS TIMESTAMP)     AS user_refund_time,
+    CAST(refund_status             AS BIGINT)        AS refund_status,
+    merchant_refund_reason                           AS merchant_refund_reason,
+    CAST(point_deduct              AS DECIMAL(20,4)) AS point_deduct,
+    CAST(shipping_cost             AS DECIMAL(20,4)) AS shipping_cost,
+    merchant_remark                                  AS merchant_remark,
+    CAST(pay_record                AS BIGINT)        AS pay_record,
+    order_sub_type                                   AS order_sub_type,
+    give_user_code                                   AS give_user_code,
+    CAST(give_order_id             AS BIGINT)        AS give_order_id,
+    CAST(read_flag                 AS BIGINT)        AS read_flag,
+    CAST(give_num                  AS BIGINT)        AS give_num,
+    CAST(invoice_id                AS BIGINT)        AS invoice_id,
+    combination_no                                   AS combination_no,
+    CAST(open_self                 AS BIGINT)        AS open_self,
+    refund_desc                                      AS refund_desc,
+    CAST(goods_allocate            AS BIGINT)        AS goods_allocate,
+    CAST(close_payment_status      AS BIGINT)        AS close_payment_status,
+    CAST(close_payment_time        AS TIMESTAMP)     AS close_payment_time,
+    CAST(finished_time             AS TIMESTAMP)     AS finished_time,
+    CAST(expire_time               AS TIMESTAMP)     AS expire_time,
+    CAST(settlement_amount         AS DECIMAL(20,4)) AS settlement_amount,
+    CAST(platform_coupon           AS BIGINT)        AS platform_coupon,
+    CAST(platform_discount         AS DECIMAL(20,4)) AS platform_discount,
+    CAST(discount_amount           AS DECIMAL(20,4)) AS discount_amount,
+    CAST(member_discount           AS DECIMAL(20,4)) AS member_discount,
+    CAST(shipping_free_id          AS BIGINT)        AS shipping_free_id,
+    CAST(shipping_free_amount      AS DECIMAL(20,4)) AS shipping_free_amount,
+    CAST(discount_point            AS BIGINT)        AS discount_point,
+    CAST(un_shipped_num            AS BIGINT)        AS un_shipped_num,
+    CAST(pre_un_shipped_num        AS BIGINT)        AS pre_un_shipped_num,
+    CAST(wait_shipped_num          AS BIGINT)        AS wait_shipped_num,
+    CAST(pre_wait_shipped_num      AS BIGINT)        AS pre_wait_shipped_num,
+    CAST(refuse_time               AS TIMESTAMP)     AS refuse_time,
+    CAST(refuse_notice             AS BIGINT)        AS refuse_notice,
+    CAST(pickup_time               AS TIMESTAMP)     AS pickup_time,
+    waring_type                                      AS waring_type,
+    CAST(waring_status             AS BIGINT)        AS waring_status,
+    point_type                                       AS point_type,
+    CAST(delivery_end_time         AS TIMESTAMP)     AS delivery_end_time,
+    CAST(serve_status              AS BIGINT)        AS serve_status,
+    CAST(self_pickup_time          AS TIMESTAMP)     AS self_pickup_time,
+    CAST(act_discount              AS DECIMAL(20,4)) AS act_discount,
+    CASE WHEN del_flg = '1' THEN TRUE ELSE FALSE END AS is_deleted,
+    act_dt                                           AS dt
+FROM (
+    SELECT *,
+        DATE_FORMAT(create_time, 'yyyyMMdd')                                        AS cdt,
+        DATE_FORMAT(COALESCE(NULLIF(update_time, ''), create_time), 'yyyyMMdd')     AS udt
+    FROM raw.tmp_trd_card_group_order_info
+    WHERE dt = '20260721'
+) t
+LATERAL VIEW explode(
+    CASE WHEN cdt = udt THEN array(udt) ELSE array(cdt, udt) END
+) e AS act_dt
+WHERE act_dt BETWEEN '20260716' AND '20260719'
+DISTRIBUTE BY act_dt;

+ 40 - 0
manual/backfill/20260721_tmp_trd_card_group_order_info_backfill_dump.ini

@@ -0,0 +1,40 @@
+; 作者:tianyu.chu
+; 日期:2026-07-21
+; 工单:(无)
+; 目的:一次性大范围补数——按 COALESCE(update_time, create_time) >= '2026-07-16' 拉当前态全量
+;       到中转表 raw.tmp_trd_card_group_order_info 单分区 dt=20260721,
+;       交给配套 rebucket 按「活动日(创建日∪变更日)」重灌 ods 的 0716~0719 分区。
+;       替代按日 re-pull —— 按日重拉会把已飘走的单丢掉,大范围当前态快照不会。
+; 状态:[待执行]
+;
+; 配套 DDL:manual/ddl/raw/trd/tmp_trd_card_group_order_info_create.sql(若 tmp 已 drop 先建)
+; 配套 rebucket:manual/backfill/20260721_ods_trd_card_group_order_info_backfill_rebucket.sql
+;
+; 运行(无 -backfill,单 job):
+;   python3 bin/datax-hive-import-starter.py \
+;     -ini manual/backfill/20260721_tmp_trd_card_group_order_info_backfill_dump.ini \
+;     -start-date 20260721 -stop-date 20260722
+;   说明:${dt}=start_date(runner.py),故传 -start-date 20260721 让数据落 dt=20260721;
+;         where 硬编码日期不吃 ${start_date},-stop-date 仅占位。
+
+[reader]
+dataSource = postgresql/prd-poyee-aliyun
+database = hobby_stocks
+table = public.card_group_order_info
+column = id,group_info_id,merchant_id,user_id,shipping_address_id,purchase_count,order_no,accounts_payable,actual_payment,payment_type,payment_time,coupon,discount,status,remark,create_time,create_by,update_time,update_by,payment_status,payment_status_desc,payment_success_time,del_flg,curier_company,refund_fee,refund_time,anonymous,pick_up_type,ship_time,refund_success_time,refund_recv_accout,refund_account,refund_request_source,card_price,act_price,goods_price_json,payment_sub_type,team_first,refuse_status,prop1,prop2,prop3,point,order_type,trade_amount,refund_type,refund_reason,evaluation,user_refund_time,refund_status,merchant_refund_reason,point_deduct,shipping_cost,merchant_remark,pay_record,order_sub_type,give_user_code,give_order_id,read_flag,give_num,invoice_id,combination_no,open_self,refund_desc,goods_allocate,close_payment_status,close_payment_time,finished_time,expire_time,settlement_amount,platform_coupon,platform_discount,discount_amount,member_discount,shipping_free_id,shipping_free_amount,discount_point,un_shipped_num,pre_un_shipped_num,wait_shipped_num,pre_wait_shipped_num,refuse_time,refuse_notice,pickup_time,waring_type,waring_status,point_type,delivery_end_time,serve_status,self_pickup_time,act_discount
+columnType =
+where = COALESCE(update_time, create_time) >= '2026-07-16'
+querySql =
+splitPk = id
+fetchSize = 1000
+
+[writer]
+dataSource = hdfs/prd-hdfs-ha
+path = /user/hive/warehouse/raw.db/tmp_trd_card_group_order_info/dt=${dt}/
+column = id,group_info_id,merchant_id,user_id,shipping_address_id,purchase_count,order_no,accounts_payable,actual_payment,payment_type,payment_time,coupon,discount,status,remark,create_time,create_by,update_time,update_by,payment_status,payment_status_desc,payment_success_time,del_flg,curier_company,refund_fee,refund_time,anonymous,pick_up_type,ship_time,refund_success_time,refund_recv_accout,refund_account,refund_request_source,card_price,act_price,goods_price_json,payment_sub_type,team_first,refuse_status,prop1,prop2,prop3,point,order_type,trade_amount,refund_type,refund_reason,evaluation,user_refund_time,refund_status,merchant_refund_reason,point_deduct,shipping_cost,merchant_remark,pay_record,order_sub_type,give_user_code,give_order_id,read_flag,give_num,invoice_id,combination_no,open_self,refund_desc,goods_allocate,close_payment_status,close_payment_time,finished_time,expire_time,settlement_amount,platform_coupon,platform_discount,discount_amount,member_discount,shipping_free_id,shipping_free_amount,discount_point,un_shipped_num,pre_un_shipped_num,wait_shipped_num,pre_wait_shipped_num,refuse_time,refuse_notice,pickup_time,waring_type,waring_status,point_type,delivery_end_time,serve_status,self_pickup_time,act_discount
+columnType =
+fileType = orc
+fileName = tmp_trd_card_group_order_info
+encoding = UTF-8
+writeMode = truncate
+fieldDelimiter = \t