Datasets:
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_datefilter); the sandbox v3 table is loaded bydsfor the corresponding date, so the SELECT has no WHERE clause and reads the full table. - The run date
dsis fixed as'20260513'and will be written as the new columnimp_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):
imp_dateSTRING: run date YYYYMMDD ='20260513'databus_imp_dateSTRING: original partition date (passed through from input)logidBIGINT, 4.svrtimeSTRING, 5.svripSTRING, 6.moduleSTRINGform_idSTRING, 8.form_typeBIGINT, 9.actionBIGINT, 10.retcodeBIGINTvidBIGINT, 12.corpidBIGINT, 13.gidBIGINTappeal_kindBIGINT (appeal problem type), 15.report_kindBIGINT (report problem type), 16.fraud_kindBIGINT (fraud type), 17.loss_amountBIGINT (loss amount)suspect_vidBIGINT, 19.suspect_corpidBIGINTorder_idSTRING (work order number), 21.order_resultBIGINT, 22.order_sourceBIGINT, 23.order_actionBIGINTmatch_ruleSTRING, 25.roomidBIGINT (problematic group number), 26.create_vidBIGINT, 27.openidSTRINGisfromwxBIGINT (interception party ww/wx), 29.spamtypeSTRING, 30.auto_finish_order_ruleSTRINGaction_timeBIGINT (action occurrence time), 32.industry_nameSTRING, 33.second_industry_nameSTRING, 34.is_kaBIGINTcreate_timeSTRING, 36.urgent_timeSTRING, 37.result_timeSTRING, 38.reopen_timeBIGINTblock_uinBIGINT, 40.block_user_id_typeBIGINT, 41.versionSTRING (v1/v2 differentiation)h5_sourceBIGINT (0: frontline customer service, 1: user self-service), 43.h5_platformBIGINT (1: BizComm, 2: PlatformW), 44.template_typeBIGINTcurrent_ownerSTRING, 46.oidBIGINT (appeal work order numeric ID), 47.reasonSTRING (QA closing evidence reason, base64)order_finish_typeSTRING, 49.reply_contentSTRING (scripted reply, base64), 50.match_rule_scene_idBIGINT
- 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 singleINSERT OVERWRITE TABLE ... SELECT. - If the target table does not exist, first create it using standard Hive format (ORC storage), then write the data.