ソースを参照

feat(raw/trd): 订单 2026 回填走中转表 + ODS 重分桶

新增一次性中转表 tmp_trd_card_group_order_info(内部表)+ 单 job dump ini
(COALESCE≥2026 全量灌 dt=20260716)+ ODS 重分桶 SQL(读中转表按 ods_dt
动态分区、DISTRIBUTE BY);替代按天串行 backfill,中间态按决策丢弃。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tianyu.chu 2 週間 前
コミット
f725985e83

+ 123 - 0
manual/backfill/20260715_ods_trd_card_group_order_info_2026rebucket.sql

@@ -0,0 +1,123 @@
+-- 作者:tianyu.chu
+-- 日期:2026-07-15
+-- 工单:(无)
+-- 目的:一次性重分桶——读中转表 raw.tmp_trd_card_group_order_info(dt=20260716) 全量 2026 单,
+--       按 ods_dt = COALESCE(update_time,create_time) 的日动态分区写入 ods(等价按天 backfill 的批量版)
+-- 状态:[待执行]
+-- 备注:动态分区 INSERT OVERWRITE 只覆盖 SELECT 出现的 ods_dt(2026 各日),不动 2026 前历史分区;
+--       DISTRIBUTE BY ods_dt 防每分区小文件(ADR-15);dump 一单一行,dedupe 实为直通、留作与日常 ODS 同构。
+--       中间态按决策丢弃:每单只落"当前最终态"到其最后变更日分区。
+--       跑完确认无误后 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,
+    ods_dt                                           AS dt
+FROM (
+    SELECT *,
+        DATE_FORMAT(COALESCE(NULLIF(update_time, ''), create_time), 'yyyyMMdd') AS ods_dt,
+        ROW_NUMBER() OVER (
+            PARTITION BY id, DATE_FORMAT(COALESCE(NULLIF(update_time, ''), create_time), 'yyyyMMdd')
+            ORDER BY COALESCE(NULLIF(update_time, ''), create_time) DESC
+        ) AS rn
+    FROM raw.tmp_trd_card_group_order_info
+    WHERE dt = '20260716'
+) t
+WHERE t.rn = 1
+DISTRIBUTE BY ods_dt;

+ 38 - 0
manual/backfill/20260715_tmp_trd_card_group_order_info_2026dump.ini

@@ -0,0 +1,38 @@
+; 作者:tianyu.chu
+; 日期:2026-07-15
+; 工单:(无)
+; 目的:一次性拉全 2026 活跃订单(当前态)到中转表 raw.tmp_trd_card_group_order_info 的单分区 dt=20260716
+;       替代按天串行 backfill —— 一个 DataX job 灌完,交给 ODS 动态分区重分桶
+; 状态:[待执行]
+;
+; 配套 DDL:manual/ddl/raw/trd/tmp_trd_card_group_order_info_create.sql
+; 配套 ODS:manual/backfill/20260715_ods_trd_card_group_order_info_2026rebucket.sql
+;
+; 运行(无 -backfill,单 job):
+;   python3 bin/datax-hive-import-starter.py \
+;     -ini manual/backfill/20260715_tmp_trd_card_group_order_info_2026dump.ini \
+;     -start-date 20260716 -stop-date 20260717
+;   说明:${dt}=start_date(runner.py),故传 -start-date 20260716 让数据落 dt=20260716;
+;         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-01-01'
+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

+ 36 - 0
manual/ddl/raw/trd/tmp_trd_card_group_order_info_create.sql

@@ -0,0 +1,36 @@
+-- 作者:tianyu.chu
+-- 日期:2026-07-15
+-- 工单:(无)
+-- 目的:一次性中转表——回填 2026 订单数据的落地区,供 ODS 重分桶后即 DROP
+-- 状态:[待执行]
+-- 生命周期:建表 → DataX 灌 dt=20260716(COALESCE≥2026 全 2026 活跃单当前态)
+--           → ODS 读 WHERE dt='20260716' 动态分区重分桶 → DROP TABLE(内部表连数据一起清)
+-- 备注:内部表(managed),DROP 自动清 HDFS 无需 hdfs rm;数据可从 PG 重抽,无兜底诉求。
+--       91 字段全 STRING,对齐 raw_trd_card_group_order_info_inc_d。
+
+DROP TABLE IF EXISTS raw.tmp_trd_card_group_order_info;
+
+CREATE TABLE IF NOT EXISTS raw.tmp_trd_card_group_order_info (
+    id STRING, group_info_id STRING, merchant_id STRING, user_id STRING, shipping_address_id STRING,
+    purchase_count STRING, order_no STRING, accounts_payable STRING, actual_payment STRING, payment_type STRING,
+    payment_time STRING, coupon STRING, discount STRING, status STRING, remark STRING,
+    create_time STRING, create_by STRING, update_time STRING, update_by STRING, payment_status STRING,
+    payment_status_desc STRING, payment_success_time STRING, del_flg STRING, curier_company STRING, refund_fee STRING,
+    refund_time STRING, anonymous STRING, pick_up_type STRING, ship_time STRING, refund_success_time STRING,
+    refund_recv_accout STRING, refund_account STRING, refund_request_source STRING, card_price STRING, act_price STRING,
+    goods_price_json STRING, payment_sub_type STRING, team_first STRING, refuse_status STRING, prop1 STRING,
+    prop2 STRING, prop3 STRING, point STRING, order_type STRING, trade_amount STRING,
+    refund_type STRING, refund_reason STRING, evaluation STRING, user_refund_time STRING, refund_status STRING,
+    merchant_refund_reason STRING, point_deduct STRING, shipping_cost STRING, merchant_remark STRING, pay_record STRING,
+    order_sub_type STRING, give_user_code STRING, give_order_id STRING, read_flag STRING, give_num STRING,
+    invoice_id STRING, combination_no STRING, open_self STRING, refund_desc STRING, goods_allocate STRING,
+    close_payment_status STRING, close_payment_time STRING, finished_time STRING, expire_time STRING, settlement_amount STRING,
+    platform_coupon STRING, platform_discount STRING, discount_amount STRING, member_discount STRING, shipping_free_id STRING,
+    shipping_free_amount STRING, discount_point STRING, un_shipped_num STRING, pre_un_shipped_num STRING, wait_shipped_num STRING,
+    pre_wait_shipped_num STRING, refuse_time STRING, refuse_notice STRING, pickup_time STRING, waring_type STRING,
+    waring_status STRING, point_type STRING, delivery_end_time STRING, serve_status STRING, self_pickup_time STRING,
+    act_discount STRING
+)
+COMMENT '订单 2026 回填一次性中转表,ODS 消费后 DROP'
+PARTITIONED BY (dt STRING)
+STORED AS ORC;