Datasets:
id: offline-compute_MySQL_mysql_015
name: Exposure Log First Exposure Time Computation
category: offline-compute/MySQL
timeout_seconds: 1800
modality: pure-text
engine: mysql
Prompt
I need you to generate a MySQL script that computes the first exposure time for each advertisement from the exposure log table.
Business Background and Objective: The advertising system periodically writes exposure logs into a summary table. Downstream consumers need to compute the first exposure time per ad ID dimension and output the corresponding minute-level timestamp string. This task filters records from the input table that meet the specified partition and conditions, groups by ad ID to obtain the minimum exposure time, formats it as a minute-level string, and writes the results to the output table.
Input Table (full name + brief description):
internal_platform_db.etl_pageview_exposure_mysql_015(exposure log detail table)
(Please connect to the database and query to confirm the table structure and field semantics.)
Processing Rules:
- Single-table processing, no joins
- Filter condition:
partition_time = 2026060914ANDad_data_model_version = 3ANDad_optimization_goal > 0 - Group by
ad_aid, computeMIN(action_imp_time)as the first exposure time - Format the first exposure time (millisecond timestamp divided by 1000 to convert to seconds) as a
yyyyMMddHHmmstring
Column Mapping Rules:
- Input column
ad_aid→ output columnaid - Aggregation result
MIN(action_imp_time)→ output columnfirst_time - Formatted string
FROM_UNIXTIME(MIN(action_imp_time)/1000, '%Y%m%d%H%i')→ output columnfirst_fen - Fixed value
2026060914→ output columndt
Output Requirements:
- Target table:
internal_platform_db.first_expo_time_cand_mysql_015 - Output field order:
aid,first_time,first_fen,dt - 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
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