dicemy's picture
Upload 655 files
e8c001c verified
|
Raw
History Blame Contribute Delete
4.31 kB
---
id: offline-compute_PySpark_pyspark_009
name: Anti-Spam H5 Work Order Log Daily Detail Sync
category: offline-compute/PySpark
timeout_seconds: 900
modality: pure-text
engine: pyspark
---
## Prompt
I need you to generate a PySpark script that synchronizes the "Anti-Spam H5 Work Order Log" from ODS to the DWD detail table with full-field passthrough, and adds a run date column.
**Business Background and Objective**: The anti-spam H5 work order service writes each appeal/report operation log to the raw `log_80001099` table (48 business fields + `databus_imp_date` partition). The downstream DWD wants to transport the full-field detail of the current day's partition every day, and additionally add a column `imp_date` (run date, YYYYMMDD) for convenient subsequent filtering by run date. The task has no aggregation and no joins — pure detail transport + one derived column.
**Input Table**:
- `internal_platform_db.caseR18_ods_log_80001099_v3`
**Data Range and Filter Conditions (business description)**:
- The original task in production reads from the full table (without `imp_date` filter); the sandbox v3 table is loaded by `ds` for the corresponding date, so the SELECT has no WHERE clause and reads the full table.
- The run date `ds` is fixed as `'20260513'` and will be written as the new column `imp_date`.
**Table Join Relationships**: (No joins, single-table passthrough.)
**Aggregation and Computation Rules (must be reflected in the SQL)**:
- Derived column `imp_date = '20260513'` (run date constant), placed as the first column in the SELECT.
- The following 49 columns are passed through as-is: `databus_imp_date` + 48 business fields, in the same order as the DDL.
- Use `INSERT OVERWRITE TABLE` + explicit column name list (50 columns) to avoid column order misalignment.
**Output Requirements**:
- Target table: `internal_platform_db.caseR18_dwd_log_80001099_daily_v3`
- Output table schema (50 columns, in this order, with the following semantics; the first 2 columns are run/original partition date, the remaining 48 are business fields):
1. `imp_date` STRING: run date YYYYMMDD = `'20260513'`
2. `databus_imp_date` STRING: original partition date (passed through from input)
3. `logid` BIGINT, 4. `svrtime` STRING, 5. `svrip` STRING, 6. `module` STRING
7. `form_id` STRING, 8. `form_type` BIGINT, 9. `action` BIGINT, 10. `retcode` BIGINT
11. `vid` BIGINT, 12. `corpid` BIGINT, 13. `gid` BIGINT
14. `appeal_kind` BIGINT (appeal problem type), 15. `report_kind` BIGINT (report problem type), 16. `fraud_kind` BIGINT (fraud type), 17. `loss_amount` BIGINT (loss amount)
18. `suspect_vid` BIGINT, 19. `suspect_corpid` BIGINT
20. `order_id` STRING (work order number), 21. `order_result` BIGINT, 22. `order_source` BIGINT, 23. `order_action` BIGINT
24. `match_rule` STRING, 25. `roomid` BIGINT (problematic group number), 26. `create_vid` BIGINT, 27. `openid` STRING
28. `isfromwx` BIGINT (interception party ww/wx), 29. `spamtype` STRING, 30. `auto_finish_order_rule` STRING
31. `action_time` BIGINT (action occurrence time), 32. `industry_name` STRING, 33. `second_industry_name` STRING, 34. `is_ka` BIGINT
35. `create_time` STRING, 36. `urgent_time` STRING, 37. `result_time` STRING, 38. `reopen_time` BIGINT
39. `block_uin` BIGINT, 40. `block_user_id_type` BIGINT, 41. `version` STRING (v1/v2 differentiation)
42. `h5_source` BIGINT (0: frontline customer service, 1: user self-service), 43. `h5_platform` BIGINT (1: BizComm, 2: PlatformW), 44. `template_type` BIGINT
45. `current_owner` STRING, 46. `oid` BIGINT (appeal work order numeric ID), 47. `reason` STRING (QA closing evidence reason, base64)
48. `order_finish_type` STRING, 49. `reply_content` STRING (scripted reply, base64), 50. `match_rule_scene_id` BIGINT
- Write strategy: `INSERT OVERWRITE TABLE` + explicit 50-column name list.
- Sandbox note: The original task is encapsulated in SparkBase (SparkJob class), using the `self.load_dw_data().createOrReplaceTempView()` + `self.save_dw_data()` chain; the sandbox version is rewritten as a top-level SparkSession + a single `INSERT OVERWRITE TABLE ... SELECT`.
- If the target table does not exist, first create it using standard Hive format (ORC storage), then write the data.