Datasets:
id: offline-compute_MySQL_mysql_009
name: 数据总线 Consumer Group Cost Detail Data Aggregation and Column Renaming
category: offline-compute/MySQL
timeout_seconds: 1800
modality: pure-text
engine: mysql
Prompt
I need you to generate a MySQL script that summarizes packet count, size, and cost from 数据总线 consumer group cost raw data, grouped by consumer group + business ID + topic, to produce a consumer group cost detail table.
Business Background and Objective: 数据总线 periodically writes cost data for each consumer group into a raw detail table. Downstream consumers only need records from the dt = '20260507' partition, grouped by business_id, topic, and consumer_group, with MAX aggregation applied to all other fields before writing to the output table. The output field names must also match the downstream table conventions. This task aggregates qualifying records from the input table, performs column renaming, and writes to the output table.
Input Table (full name + brief description):
internal_platform_db.ods_t_databus_consume_cost_final_date_d_mysql_009(数据总线 consumer group cost raw data table)
(Please connect to the database and query to confirm the table structure and field semantics.)
Filter and Aggregation Rules:
- Filter condition:
dt = '20260507' - Aggregation logic: Group by
business_id,topic,consumer_group - Apply MAX to
systemname,dwproductname,dwappgroup,cityid,iset,pkgcnt,tubesize,total_cost, andin_charge
Column Renaming Rules:
- Input column
systemname→ output columnsystem_belong - Input column
dwproductname→ output columncategory_name - Input column
dwappgroup→ output columndw_appgroup - Input column
cityid→ output columncity_id - Input column
iset→ output columncluster_set - Input column
consumer_group→ output columnconsumergroup - Input column
pkgcnt→ output columnpkg_cnt - Input column
tubesize→ output columndata_size business_id,topic,total_cost,in_chargeretain their original names
Output Requirements:
- Target table:
internal_platform_db.dwd_databus_consumergroup_cost_detail_d_cand_mysql_009 - Table comment: 数据总线 consumer group cost detail table, performing data cleansing on the ODS table
- Output field order:
dt,system_belong,category_name,dw_appgroup,city_id,cluster_set,consumergroup,business_id,topic,pkg_cnt,data_size,total_cost,in_charge - Field types:
dtVARCHAR(256),system_belongVARCHAR(256),category_nameVARCHAR(256),dw_appgroupVARCHAR(256),city_idVARCHAR(256),cluster_setVARCHAR(256),consumergroupVARCHAR(256),business_idVARCHAR(256),topicVARCHAR(256),pkg_cntBIGINT,data_sizeBIGINT,total_costDOUBLE,in_chargeVARCHAR(256) - 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