Datasets:
id: offline-compute_MySQL_mysql_002
name: Inference Service Replica Forecast and Bias Coefficient Computation
category: offline-compute/MySQL
timeout_seconds: 1800
modality: pure-text
engine: mysql
Prompt
I need you to generate a MySQL script that, for inference services with autoscaling enabled, expands hourly expected pod counts to 10-minute granularity, clips them using configured upper and lower bounds, computes a bias correction coefficient based on the actual pod count over the past 24 hours, and labels the AHPA recommended status.
Business Objective: For all inference services with autoscaling enabled (HPA or AHPA), expand the existing hourly expected pod counts to 10-minute intervals, and clip them using the service's configured replica upper and lower bounds (which must be multiplied by the machine count to convert to pod counts). Combined with the actual running pod count over the past 24 hours, compute a bias correction coefficient (actual pod count / clipped P90 expected value). Additionally, determine the AHPA service recommendation status (normal, degraded, no request). Write the final results to the target table for the partition dt='2026050700'.
Input Tables (full name + brief description):
internal_platform_db.dwd_tj_model_service_hpa_mysql_002(HPA configuration dimension table)internal_platform_db.nextgen_platform_dsl_autotune_rec_gpu_config_fht0_mysql_002(AHPA recommendation fact table)internal_platform_db.dwd_aide_inferencev2_done_service_info_h_mysql_002(service information dimension table)internal_platform_db.dwm_gputj_platform_hourly_expected_pod_mysql_002(hourly expected pod count intermediate table)internal_platform_db.dwm_gputj_platform_gpu_base_feature_agg_v2_mysql_002(actual pod count fact table)
(Please connect to the database and query to confirm the table structures and field semantics.)
Key Filters and Joins:
- Filters: The service information table must select services where
status='done', not deleted (deleted <> '1'), and with HPA or AHPA enabled. The HPA configuration table takes the latest visible configuration (first row byvisible desc, id desc). The AHPA recommendation table takes data from the last 10 minutes (current max timestamp - 600000ms). The hourly expected table takes the latest partition within the past 5 days. The actual pod count takes data from the past 24 hours (dt >= '2026050600' and dt <= '2026050700') withagg_type=2andavg_pod_count > 0. - Joins: Join all tables primarily by
service_name. The service information table is inner-joined with the hourly expected table, then left-joined with the HPA configuration table (viaservice_id = serving_id) and the AHPA status table. The hourly expected table must be cross-joined with a set of 6 time offsets (0, 10, 20, 30, 40, 50 minutes) to expand to 10-minute granularity.
Derived Logic and Business Semantics:
- Scale type: If
ahpa_enable='true', then'ahpa'; ifhpa_enable='true', then'hpa'. - AHPA recommendation status: For AHPA services, if there are no records in the last 10 minutes, the status is
'no_request'; if there are records but all haveresponse_codeother than'200', the status is'degraded'; otherwise,'normal'. - Pod count upper and lower bounds: The
min_replicasandmax_replicasfrom the HPA/AHPA configuration must be multiplied byhost_num(machine count) from the service information to obtainhpa_min_pods,hpa_max_pods,ahpa_min_pods, andahpa_max_pods. - Expected value clipping: All 8 expected pod count fields (e.g.,
expected_pod_avg_qpm_p90) must be clipped using the computed upper and lower bounds (GREATEST(LEAST(original_value, upper_bound), lower_bound)). - Bias coefficient: Bias coefficient =
actual_pod_count/ clippedexpected_pod_avg_qpm_p90value (use 1.0 when the denominator is 0). - Time expansion: Expand the hourly prediction time to 6 time points at 0, 10, 20, 30, 40, and 50 minutes of each hour (constructed using
CONCAT(SUBSTRING(agg_time,1,14), LPAD(offset,2,'0'), ':00')).
Output Requirements:
- Target table:
internal_platform_db.dwm_gputj_platform_replica_forecast_with_bias_cand_mysql_002 - Output field order:
service_name,instance_uuid,workload_name,namespace,agg_time,hour_of_day,scale_type,host_num,gpu_name,queue_name,hpa_min_pods,hpa_max_pods,ahpa_min_pods,ahpa_max_pods,ahpa_status,ahpa_response_code,expected_pod_avg_qpm_avg,expected_pod_avg_qpm_p50,expected_pod_avg_qpm_p90,expected_pod_max_qpm_avg,expected_pod_max_qpm_p50,expected_pod_max_qpm_p90,expected_pod_latest_avg_qpm,expected_pod_latest_max_qpm,actual_pod_count,bias_coefficient,dt,host_gpu_num,model_req_count agg_timeformat:yyyy-MM-dd HH:mm:00, at 10-minute granularityhour_of_dayformat:HH:00:00- Write partition:
dt='2026050700' - 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 (do not use
INSERT OVERWRITE; useINSERT INTO ... SELECT)
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