Datasets:
id: offline-compute_MySQL_mysql_020
name: Build Volume-Lift Candidate Ad List
category: offline-compute/MySQL
timeout_seconds: 1800
modality: pure-text
engine: mysql
Prompt
I need you to generate a MySQL script that builds a volume-lift candidate ad list, outputting to table internal_platform_db.dwm_union_raise_candidate_new_ads_hf_cand_mysql_020 with partition key p_partition='2026060905'.
Business Background and Objective: The ad volume-lift system needs to jointly filter qualifying ads from multiple dimensions (creative, ad group, ecology budget, advertiser, conversion link, volume-lift configuration, creative platform) to generate a candidate list for downstream consumption. This task requires multi-table JOINs, aggregation, window function ranking, and filtering across 7 input tables, ultimately writing to the output table.
Input Tables (full name + brief description):
internal_platform_db.dim_creative_info_f_mysql_020(creative information)internal_platform_db.dim_adgroup_info_f_mysql_020(ad group information)internal_platform_db.dim_adgroup_ecology_budget_info_di_mysql_020(ecology budget information)internal_platform_db.f_union_dim_advertiser_info_d_mysql_020(advertiser information)internal_platform_db.t_daily_conv_link_tid_dimension_mysql_020(conversion link dimension)internal_platform_db.dim_union_ad_raised_config_hf_mysql_020(volume-lift configuration)internal_platform_db.dim_tbl_creative_f_mysql_020(creative platform information)
(Please connect to the database and query to confirm the table structures and field semantics.)
Processing Rules:
- Main table a (
dim_creative_info_f):creative_id > 0, aggregate bycreative_idtakingMAX(adgroup_id),MAX(advertiser_id),MAX(landing_page_type) - Subquery e (
dim_adgroup_info_f) INNER JOIN:- Filter
adgroup_id > 0 - Filter
placement_group_id_listcontaining 15 or 136 (using theFIND_IN_SETfunction) begin_time >= MIN(begintime)from the config table AND<= MAX(endtime), config table conditions:partition_time = 2026060905,strategyid > 0,20260609within thebegintime-endtimerange (useFROM_UNIXTIMEto convert unix timestamps to date formatyyyyMMddfor comparison)- Aggregate by
adgroup_idtakingMAX(product_id),MAX(optimization_goal),MAX(second_optimization_goal),MAX(deep_conversion_optimization_goal),MAX(marketing_target_id),MAX(begin_time),MAX(end_time),MAX(created_time),MAX(exploration_strategy_id),MAX(placement_group_id_list)
- Filter
- Subquery b (
dim_adgroup_ecology_budget_info_di) LEFT JOIN:partition_timebetween 20260607–20260608, take the latest partition'secology_level2_idpercreative_id(using theROW_NUMBERwindow function ranked bypartition_time DESC, taking rn=1) - Subquery c (
f_union_dim_advertiser_info_d) LEFT JOIN:partition_timebetween 20260607–20260608, first aggregate byadvertiser_id + partition_timetakingMAX(operation_industry_name) AS team,MAX(short_advertiser_name), then take the latest partition'steam,short_advertiser_nameperadvertiser_id(ROW_NUMBER) - Subquery d (
t_daily_conv_link_tid_dimension) LEFT JOIN:partition_timebetween 20260607–20260608, first aggregate bytid + partition_timetakingMAX(landingpage_link_type), then take the latest partition'slandingpage_link_typepertid(ROW_NUMBER), join conditiona.creative_id = d.tid - Subquery f (
dim_tbl_creative_f) LEFT JOIN:ftid > 0, aggregate byftidtakingMAX(fsmartdeliveryplatform) AS smart_delivery_platform, join conditiona.creative_id = f.ftid - Final SELECT:
partition_time = 2026060905,adgroup_id,COALESCE(advertiser_id, 0),COALESCE(product_id, ''),CONCAT(COALESCE(optimization_goal, 0), '_', COALESCE(second_optimization_goal, 0), '_', COALESCE(deep_conversion_optimization_goal, 0)) AS mix_goal,COALESCE(landing_page_type, ''),COALESCE(marketing_target_id, 0),COALESCE(ecology_level2_id, 0),COALESCE(team, ''),COALESCE(short_advertiser_name, ''),COALESCE(landingpage_link_type, ''),COALESCE(begin_time, 0),COALESCE(end_time, 0),COALESCE(created_time, 0),COALESCE(smart_delivery_platform, 0),COALESCE(exploration_strategy_id, 0),COALESCE(placement_group_id_list, '')
Output Requirements:
- Target table:
internal_platform_db.dwm_union_raise_candidate_new_ads_hf_cand_mysql_020 - Output field order:
partition_time,adgroup_id,advertiser_id,product_id,mix_goal,landing_page_type,marketing_target_id,ecology_level2_id,team,short_advertiser_name,landingpage_link_type,begin_time,end_time,created_time,smart_delivery_platform,exploration_strategy_id,placement_group_id_list,p_partition mix_goalis generated by concatenating three optimization goal fields with underscores; null values are replaced with defaults using COALESCE (0 for numeric, empty string for string)- Final deduplication by GROUP BY on all non-
partition_timefields p_partitionis fixed as'2026060905'- If the target table does not exist, first create it using standard MySQL InnoDB format, then write the data
- Use standard MySQL syntax; do not use Hive/Spark SQL dialects (e.g.,
INSERT OVERWRITE,ARRAYtype,array_contains,concat_wsfor arrays, and other Hive-specific functions are not supported)
Environment and Execution Notes:
- Your final output must be written to the file
/tmp_workspace/result.py, notresult.sql - The local MySQL is running at localhost:3306, username
root, passwordroot123 - Use Python
pymysqlinresult.pyto execute the SQL (do not use themysqlcommand-line tool) - The script must include complete table creation (if the target table does not exist) and data writing logic
- After writing
result.py, you must executepython3 /tmp_workspace/result.pyyourself to verify that it runs successfully and produces correct data