dicemy's picture
Upload 655 files
e8c001c verified
|
Raw
History Blame Contribute Delete
3.12 kB
---
id: offline-compute_PrestoSQL_prestosql_002
name: Ad ASA Attribution Migration
category: offline-compute/PrestoSQL
timeout_seconds: 900
modality: pure-text
engine: prestosql
---
## Prompt
**Task Objective**: From the ad attribution raw logs, filter valid records of two attribution types (ad_attribution and huawei), aggregate the log count and deduplicated user count by version and media dimensions, and write the results to the output table.
**Input Table**:
- `internal_platform_db.t_sh_event_log_v2_06000061157_prestosql_002` (ad attribution raw logs)
- `ftime` STRING — time
- `extinfo` STRING — extended information
- `ad_version` STRING — ad version (ad_attribution/huawei)
- `guid` STRING — user identifier
- `ch` STRING — channel
- `first_date` STRING — first date
- `last_date` STRING — last date
- `click_date` STRING — click date
- `attribution` STRING — attribution flag
- `conversion_date` STRING — conversion date
- `conversion_type` STRING — conversion type
- `creativeset_id` STRING — creative set ID
- `org_id` STRING — organization ID
- `campaign_id` STRING — campaign ID
- `adgroup_id` STRING — ad group ID
- `keyword_id` STRING — keyword ID
- `country_oregion` STRING — country/region
- `enter_ag_time` STRING — ad group entry time
- `installed_finish_time` STRING — installation completion time
- `start_download_time` STRING — download start time
- `sub_channel` STRING — sub-channel
- `callback` STRING — callback information
- `task_id` STRING — task ID
- `sub_task_id` STRING — sub-task ID
- `rta_id` STRING — RTA identifier
- `device_id` STRING — device_id identifier
- `ext_info1` STRING — extended information 1
- `ext_info2` STRING — extended information 2
- `caid` STRING — CAID
- `claim_type` STRING — claim type
- `ai_assistant_device_id` STRING — YB device_id
- `ds` STRING — partition field
**Filter Conditions**:
- `ds = '2026060919'`
- Valid record condition: `(ad_version = 'ad_attribution' AND attribution = 'true') OR (ad_version = 'phonebrandh' AND callback != '')`
**Output Requirements**:
- Target table: `internal_platform_db.t_my_ads_tracking_log_metrics_cand_prestosql_002`
- Output fields and order: `ds` BIGINT, `ad_version` STRING, `media_id` INT, `log_num` BIGINT, `log_num_qimei` BIGINT
- `ds`: Cast the original table's `ds` field to BIGINT
- `media_id`: `CASE ad_version WHEN 'ad_attribution' THEN 39 WHEN 'phonebrandh' THEN 28 END`
- `log_num`: `COUNT(*)` log count
- `log_num_qimei`: `COUNT(DISTINCT device_id)` deduplicated user count
- Group by `ds`, `ad_version`
- 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