| --- |
| id: offline-compute_PrestoSQL_prestosql_006 |
| name: News Plugin Send Process Multi-Dimensional Aggregation |
| category: offline-compute/PrestoSQL |
| timeout_seconds: 900 |
| modality: pure-text |
| engine: prestosql |
| --- |
| ## Prompt |
| **Task Objective**: From the news plugin send process flow table, aggregate and compute metrics such as send count, send UV, panel exposure count, panel exposure UV, inner-page PV, and inner-page UV by the scene (`pos_desc`) dimension, across two time windows — current day and last 1 hour — and write the results to the output table. |
|
|
| **Input Table**: |
| - `internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006` (news plugin send process flow table) |
| - `imp_hour` BIGINT — hourly partition |
| - `user_id` STRING — user ID |
| - `content_id` STRING — content ID |
| - `push_id` STRING — push ID |
| - `pos` STRING — position |
| - `send_cnt` BIGINT — send count |
| - `panel_exp_cnt` BIGINT — panel exposure count |
| - `pgin_pv` BIGINT — inner-page PV |
| - `pos_desc` STRING — position description (scene) |
| - `account_code` STRING — business code |
|
|
| **Output Requirements**: |
| - Target table: `internal_platform_db.ads_news_plugin_ai_assistant_hourly_report_cand_prestosql_006` |
| - Output fields and order: |
| - `imp_hour` BIGINT — hourly partition |
| - `scene` STRING — scene (`pos_desc`) |
| - `send_cnt_dth` BIGINT — current day send count (`SUM(send_cnt) WHERE imp_hour <= current hour`) |
| - `send_uv_dth` BIGINT — current day send UV (`COUNT(DISTINCT user_id) WHERE imp_hour <= current hour`) |
| - `panel_exp_cnt_dth` BIGINT — current day panel exposure count (`SUM(panel_exp_cnt) WHERE imp_hour <= current hour`) |
| - `panel_exp_uv_dth` BIGINT — current day panel exposure UV (`COUNT(DISTINCT user_id) WHERE panel_exp_cnt > 0 AND imp_hour <= current hour`) |
| - `pgin_pv_dth` BIGINT — current day inner-page PV (`SUM(pgin_pv) WHERE imp_hour <= current hour`) |
| - `pgin_uv_dth` BIGINT — current day inner-page UV (`COUNT(DISTINCT user_id) WHERE pgin_pv > 0 AND imp_hour <= current hour`) |
| - `send_cnt_1h` BIGINT — last 1 hour send count (`SUM(send_cnt) WHERE imp_hour = current hour`) |
| - `send_uv_1h` BIGINT — last 1 hour send UV |
| - `panel_exp_cnt_1h` BIGINT — last 1 hour panel exposure count |
| - `panel_exp_uv_1h` BIGINT — last 1 hour panel exposure UV |
| - `pgin_pv_1h` BIGINT — last 1 hour inner-page PV |
| - `pgin_uv_1h` BIGINT — last 1 hour inner-page UV |
|
|
| - Simplified explanation: For each `imp_hour` + `pos_desc` combination, compute the current day cumulative (dth) and current hour (1h) aggregation metrics |
| - If the target table does not exist, first create the table, then write the data |
| - Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects |
|
|
| **Environment and Execution Notes**: |
| - Presto is running, connected via the Hive catalog |
| - Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql` |
| - After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data |
|
|