Datasets:
id: offline-compute_MySQL_mysql_004
name: Ceph Path Coldness Score Cluster-Level Statistics
category: offline-compute/MySQL
timeout_seconds: 1800
modality: pure-text
engine: mysql
Prompt
Please generate MySQL code based on the following requirements.
Task Objective Perform cluster-level statistics on Ceph path coldness score data using three aggregation methods, and write the results to the target table.
Input
- Input table:
internal_platform_db.t_ceph_path_coldness_score_v2_mysql_004 - Filter condition:
dt='20260507'
- Processing Rules 3.1 Three path selection method definitions:
level2_only: Select only records wherepath_level=2max_available: For eachcluster_name, group by the first-level directory ofpath_level2(group key = the first segment obtained by removing the leading/frompath_level2and splitting by/; for example,/data/logsand/data/backupboth have the group keydata). For each group, select the record with the maximumpath_level.leaf_only: Select leaf nodes (i.e., records for which no other record with the samecluster_nameexists whosepath_level2equals the parent path obtained by removing the last/and everything after it from the current record'spath_level2; for example, if the current path is/data/logs/app1, the parent path is/data/logs, and if a record with this parent path exists, the current record is not a leaf).
3.2 After merging the data from all three methods, aggregate by cluster_name and agg_method:
total_path_count: Total path count (count)total_size_tb: Total capacity in TB (sum)total_access_count: Total access count (sum)avg_coldness_score: Average coldness score (mean)cluster_heat_category: Categorize based onavg_coldness_score: >=60 is'高热集群'(high-heat cluster), >=40 is'较热集群'(warm cluster), >=20 is'中等集群'(moderate cluster), otherwise'较冷集群'(cool cluster)p0_count/p0_size_tb: Path count/capacity wheregovernance_level='P0'p1_count/p1_size_tb: Path count/capacity wheregovernance_level='P1'p2_count/p2_size_tb: Path count/capacity wheregovernance_level='P2'p3_count/p3_size_tb: Path count/capacity wheregovernance_level='P3'cold_path_pct: (P0 path count + P1 path count) / total path count * 100cold_size_pct: (P0 capacity + P1 capacity) / total capacity * 100
Output Requirements Output field order:
cluster_name(VARCHAR(256)),agg_method(VARCHAR(256)),total_path_count(BIGINT),total_size_tb(DOUBLE),total_access_count(BIGINT),avg_coldness_score(DOUBLE),cluster_heat_category(VARCHAR(256)),p0_count(BIGINT),p0_size_tb(DOUBLE),p1_count(BIGINT),p1_size_tb(DOUBLE),p2_count(BIGINT),p2_size_tb(DOUBLE),p3_count(BIGINT),p3_size_tb(DOUBLE),cold_path_pct(DOUBLE),cold_size_pct(DOUBLE),dt(VARCHAR(256))Write Requirements
- Output table:
internal_platform_db.t_ceph_coldness_cluster_stats_v2_cand_mysql_004 - Filter condition:
dt='20260507' - No joins, single-table processing
- 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