| --- |
| 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. |
|
|
| 1. Task Objective |
| Perform cluster-level statistics on Ceph path coldness score data using three aggregation methods, and write the results to the target table. |
|
|
| 2. Input |
| - Input table: `internal_platform_db.t_ceph_path_coldness_score_v2_mysql_004` |
| - Filter condition: `dt='20260507'` |
|
|
| 3. Processing Rules |
| 3.1 Three path selection method definitions: |
| - `level2_only`: Select only records where `path_level=2` |
| - `max_available`: For each `cluster_name`, group by the first-level directory of `path_level2` (group key = the first segment obtained by removing the leading `/` from `path_level2` and splitting by `/`; for example, `/data/logs` and `/data/backup` both have the group key `data`). For each group, select the record with the maximum `path_level`. |
| - `leaf_only`: Select leaf nodes (i.e., records for which no other record with the same `cluster_name` exists whose `path_level2` equals the parent path obtained by removing the last `/` and everything after it from the current record's `path_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 on `avg_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 where `governance_level='P0'` |
| - `p1_count`/`p1_size_tb`: Path count/capacity where `governance_level='P1'` |
| - `p2_count`/`p2_size_tb`: Path count/capacity where `governance_level='P2'` |
| - `p3_count`/`p3_size_tb`: Path count/capacity where `governance_level='P3'` |
| - `cold_path_pct`: (P0 path count + P1 path count) / total path count * 100 |
| - `cold_size_pct`: (P0 capacity + P1 capacity) / total capacity * 100 |
|
|
| 4. 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)) |
|
|
| 5. 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`, not `result.sql` |
| - The local MySQL is running at localhost:3306, username `root`, password `root123` |
| - Use Python `pymysql` in `result.py` to execute the SQL (do not use the `mysql` command-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 execute `python3 /tmp_workspace/result.py` yourself to verify that it runs successfully and produces correct data |
|
|