| {"task_id": "prestosql_001", "id": "offline-compute_PrestoSQL_prestosql_001", "name": "安全扫描实例明细分析", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n任务目标:从安全扫描 span 信息和资源分配信息关联产出安全扫描实例运行明细表。\n\n输入:\n- internal_platform_db.t_security_scan_span_prestosql_001\n- internal_platform_db.t_security_resource_info_prestosql_001\n\n处理规则:\n- 两表关联查询,关联条件需基于表结构确定\n- 具体过滤条件和字段选择需基于表结构确定\n\n输出要求:\n- 输出表:internal_platform_db.t_security_scan_instance_detail_cand_prestosql_001\n- 输出字段需基于目标表结构确定\n\n写入要求:\n- 写入目标表\n\n请将最终 Presto/Trino SQL 写入 result.sql 并执行。", "ground_truth": "INSERT INTO internal_platform_db.t_security_scan_instance_detail_prestosql_001\nWITH base_trace AS (\n SELECT trace_id\n FROM internal_platform_db.t_security_scan_span_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND span_name IN ('scan.completed', 'scan.failed')\n GROUP BY trace_id\n HAVING\n COUNT(CASE WHEN span_name = 'scan.failed' THEN 1 END) > 0\n AND\n COUNT(CASE WHEN span_name = 'scan.completed' THEN 1 END) = 0\n),\ncombined_spans AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n security_project_id,\n security_task_id,\n scan_type,\n status_code\n FROM internal_platform_db.t_security_scan_span_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('scan.failed', 'scan.start', 'scan.execute', 'scan.cleanup', 'resource.allocate')\n\n UNION ALL\n\n SELECT\n trace_id,\n 'scan.completed' AS span_name,\n MAX(CASE WHEN span_name = 'scan.start' THEN start_time END) AS start_time,\n MAX(CASE WHEN span_name = 'scan.failed' THEN end_time END) AS end_time,\n MAX(CASE WHEN span_name = 'scan.failed' THEN security_project_id END) AS security_project_id,\n MAX(CASE WHEN span_name = 'scan.failed' THEN security_task_id END) AS security_task_id,\n MAX(CASE WHEN span_name = 'scan.failed' THEN scan_type END) AS scan_type,\n 2 AS status_code\n FROM internal_platform_db.t_security_scan_span_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('scan.start', 'scan.failed')\n GROUP BY trace_id\n),\nbase_data_time_fixed AS (\n SELECT\n trace_id,\n span_name,\n CASE\n WHEN span_name = 'scan.failed'\n THEN MIN(CASE WHEN span_name IN ('scan.execute', 'scan.failed') THEN start_time END)\n OVER(PARTITION BY trace_id)\n ELSE start_time\n END AS start_time,\n end_time,\n security_project_id,\n security_task_id,\n scan_type,\n status_code\n FROM combined_spans\n),\nbase_data AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n security_project_id,\n security_task_id,\n scan_type,\n status_code,\n from_unixtime(CAST(start_time AS BIGINT) / 1000) AS start_date,\n from_unixtime(CAST(end_time AS BIGINT) / 1000) AS end_date,\n date_diff('day', from_unixtime(CAST(start_time AS BIGINT) / 1000), from_unixtime(CAST(end_time AS BIGINT) / 1000)) AS diff_days,\n CAST(CAST(start_time AS BIGINT) / 86400000 AS BIGINT) * 86400000 AS start_day_midnight_ms\n FROM base_data_time_fixed\n),\npos_series AS (\n SELECT 0 AS pos UNION ALL SELECT 1 AS pos UNION ALL SELECT 2 AS pos UNION ALL SELECT 3 AS pos\n),\ndaily_split_spans AS (\n SELECT\n b.trace_id,\n b.span_name,\n b.security_project_id,\n b.security_task_id,\n b.scan_type,\n b.status_code,\n b.start_date,\n b.end_date,\n b.diff_days,\n date_add('day', s.pos, b.start_date) AS calc_date,\n CASE WHEN s.pos = 0 THEN b.start_time\n ELSE CAST(b.start_day_midnight_ms + s.pos * 86400000 AS VARCHAR)\n END AS start_time,\n CASE WHEN s.pos = b.diff_days THEN b.end_time\n ELSE CAST(b.start_day_midnight_ms + (s.pos + 1) * 86400000 - 1 AS VARCHAR)\n END AS end_time,\n b.start_time AS span_start_time,\n b.end_time AS span_end_time\n FROM base_data b\n INNER JOIN pos_series s ON s.pos <= b.diff_days\n),\ntrace_time_metrics AS (\n SELECT\n t.trace_id,\n t.calc_date,\n MAX(t.security_project_id) AS security_project_id,\n MAX(t.security_task_id) AS security_task_id,\n MAX(t.scan_type) AS scan_type,\n MAX(MAX(CASE WHEN t.span_name = 'scan.completed' THEN t.status_code END)) OVER(PARTITION BY t.trace_id) AS status_code,\n CAST(ROUND((MAX(CASE WHEN t.span_name = 'scan.execute' THEN CAST(t.end_time AS BIGINT) END) -\n MIN(CASE WHEN t.span_name = 'scan.execute' THEN CAST(t.start_time AS BIGINT) END)) / 1000.0) AS INT) AS scan_run_time,\n CAST(ROUND((MAX(CASE WHEN t.span_name IN ('scan.execute', 'scan.cleanup') THEN CAST(t.end_time AS BIGINT) END) -\n MIN(CASE WHEN t.span_name IN ('scan.execute', 'scan.cleanup') THEN CAST(t.start_time AS BIGINT) END)) / 1000.0) AS INT) AS code_run_time,\n CAST(ROUND((MAX(CASE WHEN t.span_name = 'resource.allocate' THEN CAST(t.end_time AS BIGINT) END) -\n MIN(CASE WHEN t.span_name = 'resource.allocate' THEN CAST(t.start_time AS BIGINT) END)) / 1000.0) AS INT) AS resource_wait_time\n FROM daily_split_spans t\n GROUP BY t.trace_id, t.calc_date\n)\nSELECT\n date_format(t1.calc_date, '%Y-%m-%d') AS p_date,\n t1.trace_id,\n t1.security_project_id,\n t1.security_task_id,\n t1.scan_type,\n t1.status_code,\n t1.scan_run_time,\n t1.code_run_time,\n t1.resource_wait_time,\n t2.resource_id,\n CAST(t2.is_dedicated AS BOOLEAN) AS is_dedicated,\n t2.apply_for_cpu_count\nFROM trace_time_metrics t1\nLEFT JOIN (\n SELECT\n trace_id,\n MAX(resource_id) AS resource_id,\n MAX(is_dedicated) AS is_dedicated,\n MAX(cpu_cores) AS apply_for_cpu_count\n FROM internal_platform_db.t_security_resource_info_prestosql_001\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n GROUP BY trace_id\n) t2 ON t1.trace_id = t2.trace_id\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_001"} |
| {"task_id": "prestosql_002_en", "id": "offline-compute_PrestoSQL_prestosql_002", "name": "Ad ASA Attribution Migration", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the ad attribution raw logs, filter valid records of two attribution types (ad_attribution and huawei), aggregate the log count and deduplicated user count by version and media dimensions, and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.t_sh_event_log_v2_06000061157_prestosql_002` (ad attribution raw logs)\n - `ftime` STRING — time\n - `extinfo` STRING — extended information\n - `ad_version` STRING — ad version (ad_attribution/huawei)\n - `guid` STRING — user identifier\n - `ch` STRING — channel\n - `first_date` STRING — first date\n - `last_date` STRING — last date\n - `click_date` STRING — click date\n - `attribution` STRING — attribution flag\n - `conversion_date` STRING — conversion date\n - `conversion_type` STRING — conversion type\n - `creativeset_id` STRING — creative set ID\n - `org_id` STRING — organization ID\n - `campaign_id` STRING — campaign ID\n - `adgroup_id` STRING — ad group ID\n - `keyword_id` STRING — keyword ID\n - `country_oregion` STRING — country/region\n - `enter_ag_time` STRING — ad group entry time\n - `installed_finish_time` STRING — installation completion time\n - `start_download_time` STRING — download start time\n - `sub_channel` STRING — sub-channel\n - `callback` STRING — callback information\n - `task_id` STRING — task ID\n - `sub_task_id` STRING — sub-task ID\n - `rta_id` STRING — RTA identifier\n - `device_id` STRING — device_id identifier\n - `ext_info1` STRING — extended information 1\n - `ext_info2` STRING — extended information 2\n - `caid` STRING — CAID\n - `claim_type` STRING — claim type\n - `ai_assistant_device_id` STRING — YB device_id\n - `ds` STRING — partition field\n\n**Filter Conditions**:\n- `ds = '2026060919'`\n- Valid record condition: `(ad_version = 'ad_attribution' AND attribution = 'true') OR (ad_version = 'phonebrandh' AND callback != '')`\n\n**Output Requirements**:\n- Target table: `internal_platform_db.t_my_ads_tracking_log_metrics_cand_prestosql_002`\n- Output fields and order: `ds` BIGINT, `ad_version` STRING, `media_id` INT, `log_num` BIGINT, `log_num_qimei` BIGINT\n- `ds`: Cast the original table's `ds` field to BIGINT\n- `media_id`: `CASE ad_version WHEN 'ad_attribution' THEN 39 WHEN 'phonebrandh' THEN 28 END`\n- `log_num`: `COUNT(*)` log count\n- `log_num_qimei`: `COUNT(DISTINCT device_id)` deduplicated user count\n- Group by `ds`, `ad_version`\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.t_my_ads_tracking_log_metrics_prestosql_002\nSELECT\n CAST(ds AS BIGINT) AS ds,\n ad_version,\n CASE ad_version WHEN 'ad_attribution' THEN 39 WHEN 'phonebrandh' THEN 28 END AS media_id,\n COUNT(*) AS log_num,\n COUNT(DISTINCT device_id) AS log_num_qimei\nFROM internal_platform_db.t_sh_event_log_v2_06000061157_prestosql_002\nWHERE ds = '2026060919'\n AND ((ad_version = 'ad_attribution' AND attribution = 'true')\n OR (ad_version = 'phonebrandh' AND callback != ''))\nGROUP BY ds, ad_version", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_002_en"} |
| {"task_id": "prestosql_003", "id": "offline-compute_PrestoSQL_prestosql_003", "name": "IM平台Q群离线报告子分区过滤", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:从IM平台Q群离线报告原始日志中,筛选指定appid下包含\"诈骗\"标签的记录,提取关键字段写入输出表。\n\n**输入表**:\n- `internal_platform_db.dwd_t_event_log_v1_05900072467_with_subpartition_hi_prestosql_003`(IM平台Q群离线报告原始日志)\n - `databus_imp_date` STRING — 数据日期\n - `ftime` STRING — 时间\n - `appid` STRING — 应用ID\n - `message_id` STRING — 消息ID\n - `reqbody` STRING — 请求体(JSON)\n - `content` STRING — 内容\n - `model_id` STRING — 模型ID\n - `group_num` STRING — 群号\n - `punish_path_name` STRING — 处罚路径名称\n - `ext_field1` STRING — 扩展字段1\n - `ext_field2` STRING — 扩展字段2\n - `ds` BIGINT — 分区字段\n\n**过滤条件**:\n- `appid = '100553'`\n- `reqbody IS NOT NULL`\n- `get_json_object(reqbody, '$.tag_info') IS NOT NULL`\n- `get_json_object(reqbody, '$.tag_info.tag_result_text') LIKE '%诈骗-%'`\n- `ftime = '20250324'`\n\n**输出要求**:\n- 目标表: `internal_platform_db.dwd_qqgroup_offline_report_cand_prestosql_003`\n- 输出字段及顺序: `ftime` STRING, `appid` STRING, `model_id` STRING, `message_id` STRING, `databus_imp_date` STRING, `group_num` STRING, `punish_path_name` STRING, `content` STRING\n- appid 固定值 '101069'\n- model_id 固定值 'IM平台Qgroup_zhapian_report_1049'\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n- 注意:Presto中使用json_extract_scalar代替get_json_object\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.dwd_qqgroup_offline_report_prestosql_003\nSELECT\n ftime,\n '101069' AS appid,\n 'IM平台Qgroup_zhapian_report_1049' AS model_id,\n message_id,\n databus_imp_date,\n group_num,\n punish_path_name,\n content\nFROM internal_platform_db.dwd_t_event_log_v1_05900072467_with_subpartition_hi_prestosql_003\nWHERE appid = '100553'\n AND reqbody IS NOT NULL\n AND get_json_object(reqbody, '$.tag_info') IS NOT NULL\n AND get_json_object(reqbody, '$.tag_info.tag_result_text') LIKE '%诈骗-%'\n AND ftime = '20250324'", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_003"} |
| {"task_id": "prestosql_004", "id": "offline-compute_PrestoSQL_prestosql_004", "name": "小说UDS算法书籍关系筛选", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:从小说UDS算法书籍关系表中,筛选指定事件类型的记录,根据事件类型映射为操作类型,提取关键字段写入输出表。\n\n**输入表**:\n- `internal_platform_db.t_oh_novel_uds_algorithm_book_rel_prestosql_004`(小说UDS算法书籍关系表)\n - `ftime` STRING — 时间\n - `event_code` STRING — 事件编码\n - `book_id` STRING — 书籍ID\n - `guid` STRING — 用户标识\n - `reqid` STRING — 请求ID\n - `traceid` STRING — 追踪ID\n - `report_time` STRING — 上报时间\n - `ds` BIGINT — 分区字段\n\n**过滤条件**:\n- `ds = 2026060906`\n- `length(book_id) = 10`\n- `event_code IN ('expose', 'click', 'real_read', 'add_0', 'add_1', 'shelf_add', 'share', 'comment', 'like')`\n\n**输出要求**:\n- 目标表: `internal_platform_db.t_od_novel_user_action_detail_cand_prestosql_004`\n- 输出字段及顺序: `reqid` STRING, `guid` STRING, `bookid` STRING, `traceid` STRING, `action` STRING, `ftime` STRING, `report_time` STRING\n- action: CASE event_code WHEN 'expose' THEN 'expose' WHEN 'click' THEN 'click' WHEN 'real_read' THEN 'real_read' WHEN 'add_0' THEN 'add_0' WHEN 'add_1' THEN 'add_1' ELSE event_code END\n- bookid: book_id\n- traceid: substr(traceid, 1, 4)\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.t_od_novel_user_action_detail_prestosql_004\nSELECT\n reqid,\n guid,\n book_id AS bookid,\n substr(traceid, 1, 4) AS traceid,\n CASE event_code\n WHEN 'expose' THEN 'expose'\n WHEN 'click' THEN 'click'\n WHEN 'real_read' THEN 'real_read'\n WHEN 'add_0' THEN 'add_0'\n WHEN 'add_1' THEN 'add_1'\n ELSE event_code\n END AS action,\n ftime,\n report_time\nFROM internal_platform_db.t_oh_novel_uds_algorithm_book_rel_prestosql_004\nWHERE ds = 2026060906\n AND length(book_id) = 10\n AND event_code IN ('expose', 'click', 'real_read', 'add_0', 'add_1', 'shelf_add', 'share', 'comment', 'like')", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_004"} |
| {"task_id": "prestosql_005_en", "id": "offline-compute_PrestoSQL_prestosql_005", "name": "Hot Table Governance Metadata Wide Table Aggregation", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the hot table governance metadata detail table, filter valid hot table records (heat > 0, excluding temporary/test tables), aggregate by database name and table name to take the maximum of each metric, and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.ads_gov_cost_table_govern_detail_df_prestosql_005` (hot table governance metadata detail table)\n - `imp_date` BIGINT — date partition\n - `db_name` STRING — database name\n - `table_name` STRING — table name\n - `heat` BIGINT — heat\n - `owner` STRING — owner\n - `storage_detail` DOUBLE — storage detail\n - `task_cnt` BIGINT — task count\n - `table_type` STRING — table type\n - `govern_status` STRING — governance status\n - `last_access_time` STRING — last access time\n - `table_comment` STRING — table comment\n - `partition_cnt` BIGINT — partition count\n - `file_format` STRING — file format\n - `table_size` DOUBLE — table size\n - `avg_file_size` DOUBLE — average file size\n - `is_partitioned` INT — whether partitioned\n - `lifecycle_days` INT — lifecycle days\n - `create_time` STRING — creation time\n - `modify_time` STRING — modification time\n - `project_name` STRING — project name\n\n**Filter Conditions**:\n- `imp_date = 20260507`\n- `heat > 0`\n- `table_name NOT LIKE '%temp%'`\n- `db_name NOT LIKE '%test%'`\n\n**Output Requirements**:\n- Target table: `internal_platform_db.dwd_hot_metadata_table_cand_prestosql_005`\n- Output fields and order: `dt` STRING, `db_name` STRING, `table_name` STRING, `owner` STRING, `storage_detail` DOUBLE, `heat` BIGINT, `task_cnt` BIGINT, `table_type` STRING, `govern_status` STRING, `last_access_time` STRING, `table_comment` STRING, `partition_cnt` BIGINT, `file_format` STRING, `table_size` DOUBLE, `avg_file_size` DOUBLE, `is_partitioned` INT, `lifecycle_days` INT, `create_time` STRING, `modify_time` STRING, `project_name` STRING\n- `dt`: Fixed value `'20260507'`\n- Group by `db_name`, `table_name`, apply `MAX()` to all other fields\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.dwd_hot_metadata_table_prestosql_005\nSELECT\n '20260507' AS dt,\n db_name,\n table_name,\n MAX(owner) AS owner,\n MAX(storage_detail) AS storage_detail,\n MAX(heat) AS heat,\n MAX(task_cnt) AS task_cnt,\n MAX(table_type) AS table_type,\n MAX(govern_status) AS govern_status,\n MAX(last_access_time) AS last_access_time,\n MAX(table_comment) AS table_comment,\n MAX(partition_cnt) AS partition_cnt,\n MAX(file_format) AS file_format,\n MAX(table_size) AS table_size,\n MAX(avg_file_size) AS avg_file_size,\n MAX(is_partitioned) AS is_partitioned,\n MAX(lifecycle_days) AS lifecycle_days,\n MAX(create_time) AS create_time,\n MAX(modify_time) AS modify_time,\n MAX(project_name) AS project_name\nFROM internal_platform_db.ads_gov_cost_table_govern_detail_df_prestosql_005\nWHERE imp_date = 20260507\n AND heat > 0\n AND table_name NOT LIKE '%temp%'\n AND db_name NOT LIKE '%test%'\nGROUP BY db_name, table_name", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_005_en"} |
| {"task_id": "prestosql_006_en", "id": "offline-compute_PrestoSQL_prestosql_006", "name": "News Plugin Send Process Multi-Dimensional Aggregation", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the news plugin send process flow table, aggregate and compute metrics such as send count, send UV, panel exposure count, panel exposure UV, inner-page PV, and inner-page UV by the scene (`pos_desc`) dimension, across two time windows — current day and last 1 hour — and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006` (news plugin send process flow table)\n - `imp_hour` BIGINT — hourly partition\n - `user_id` STRING — user ID\n - `content_id` STRING — content ID\n - `push_id` STRING — push ID\n - `pos` STRING — position\n - `send_cnt` BIGINT — send count\n - `panel_exp_cnt` BIGINT — panel exposure count\n - `pgin_pv` BIGINT — inner-page PV\n - `pos_desc` STRING — position description (scene)\n - `account_code` STRING — business code\n\n**Output Requirements**:\n- Target table: `internal_platform_db.ads_news_plugin_ai_assistant_hourly_report_cand_prestosql_006`\n- Output fields and order:\n - `imp_hour` BIGINT — hourly partition\n - `scene` STRING — scene (`pos_desc`)\n - `send_cnt_dth` BIGINT — current day send count (`SUM(send_cnt) WHERE imp_hour <= current hour`)\n - `send_uv_dth` BIGINT — current day send UV (`COUNT(DISTINCT user_id) WHERE imp_hour <= current hour`)\n - `panel_exp_cnt_dth` BIGINT — current day panel exposure count (`SUM(panel_exp_cnt) WHERE imp_hour <= current hour`)\n - `panel_exp_uv_dth` BIGINT — current day panel exposure UV (`COUNT(DISTINCT user_id) WHERE panel_exp_cnt > 0 AND imp_hour <= current hour`)\n - `pgin_pv_dth` BIGINT — current day inner-page PV (`SUM(pgin_pv) WHERE imp_hour <= current hour`)\n - `pgin_uv_dth` BIGINT — current day inner-page UV (`COUNT(DISTINCT user_id) WHERE pgin_pv > 0 AND imp_hour <= current hour`)\n - `send_cnt_1h` BIGINT — last 1 hour send count (`SUM(send_cnt) WHERE imp_hour = current hour`)\n - `send_uv_1h` BIGINT — last 1 hour send UV\n - `panel_exp_cnt_1h` BIGINT — last 1 hour panel exposure count\n - `panel_exp_uv_1h` BIGINT — last 1 hour panel exposure UV\n - `pgin_pv_1h` BIGINT — last 1 hour inner-page PV\n - `pgin_uv_1h` BIGINT — last 1 hour inner-page UV\n\n- Simplified explanation: For each `imp_hour` + `pos_desc` combination, compute the current day cumulative (dth) and current hour (1h) aggregation metrics\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.ads_news_plugin_ai_assistant_hourly_report_prestosql_006\nSELECT\n h.imp_hour,\n h.pos_desc AS scene,\n h.send_cnt_dth,\n h.send_uv_dth,\n h.panel_exp_cnt_dth,\n h.panel_exp_uv_dth,\n h.pgin_pv_dth,\n h.pgin_uv_dth,\n h.send_cnt_1h,\n h.send_uv_1h,\n h.panel_exp_cnt_1h,\n h.panel_exp_uv_1h,\n h.pgin_pv_1h,\n h.pgin_uv_1h\nFROM (\n SELECT\n t1.imp_hour,\n t1.pos_desc,\n t1.send_cnt AS send_cnt_dth,\n t1.send_uv AS send_uv_dth,\n t1.panel_exp_cnt AS panel_exp_cnt_dth,\n t1.panel_exp_uv AS panel_exp_uv_dth,\n t1.pgin_pv AS pgin_pv_dth,\n t1.pgin_uv AS pgin_uv_dth,\n t2.send_cnt AS send_cnt_1h,\n t2.send_uv AS send_uv_1h,\n t2.panel_exp_cnt AS panel_exp_cnt_1h,\n t2.panel_exp_uv AS panel_exp_uv_1h,\n t2.pgin_pv AS pgin_pv_1h,\n t2.pgin_uv AS pgin_uv_1h\n FROM (\n SELECT\n a.imp_hour,\n a.pos_desc,\n SUM(b.send_cnt) AS send_cnt,\n COUNT(DISTINCT b.user_id) AS send_uv,\n SUM(b.panel_exp_cnt) AS panel_exp_cnt,\n COUNT(DISTINCT CASE WHEN b.panel_exp_cnt > 0 THEN b.user_id END) AS panel_exp_uv,\n SUM(b.pgin_pv) AS pgin_pv,\n COUNT(DISTINCT CASE WHEN b.pgin_pv > 0 THEN b.user_id END) AS pgin_uv\n FROM (SELECT DISTINCT imp_hour, pos_desc FROM internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006) a\n JOIN internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006 b\n ON a.pos_desc = b.pos_desc AND b.imp_hour <= a.imp_hour\n GROUP BY a.imp_hour, a.pos_desc\n ) t1\n JOIN (\n SELECT\n imp_hour,\n pos_desc,\n SUM(send_cnt) AS send_cnt,\n COUNT(DISTINCT user_id) AS send_uv,\n SUM(panel_exp_cnt) AS panel_exp_cnt,\n COUNT(DISTINCT CASE WHEN panel_exp_cnt > 0 THEN user_id END) AS panel_exp_uv,\n SUM(pgin_pv) AS pgin_pv,\n COUNT(DISTINCT CASE WHEN pgin_pv > 0 THEN user_id END) AS pgin_uv\n FROM internal_platform_db.dwm_news_plugin_ai_assistant_send_process_flow_hi_prestosql_006\n GROUP BY imp_hour, pos_desc\n ) t2 ON t1.imp_hour = t2.imp_hour AND t1.pos_desc = t2.pos_desc\n) h", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_006_en"} |
| {"task_id": "prestosql_007_en", "id": "offline-compute_PrestoSQL_prestosql_007", "name": "APK Threat Scan Instance GPU Card-Hour 5-Minute Window Statistics", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: Compute the GPU card-hour consumption of APK scan instances, aggregated by 5-minute time windows, joining with Pod mapping and task instance GPU configuration information, and write the results to the output table.\n\n**Input Tables**:\n- `internal_platform_db.t_gpu_monitor_parsed_prestosql_007` (GPU monitoring data table)\n - `container` STRING — container name\n - `pod_name` STRING — Pod name\n - `pkg_time` STRING — reporting time (epoch second string)\n - `gpu_name` STRING — GPU model\n - `metric` STRING — metric name\n - `value` STRING — metric value\n - `dt` STRING — partition field (format `'2026060800'`)\n\n- `internal_platform_db.dwd_scan_instance_podname_prestosql_007` (Pod-to-scan-instance mapping table)\n - `dt` STRING — partition field\n - `instance_uuid` STRING — instance unique identifier\n - `pod_name` STRING — Pod name\n - `pod_phase` STRING — Pod phase\n - `namespace` STRING — namespace\n\n- `internal_platform_db.dwd_scan_task_instance_prestosql_007` (task instance GPU configuration table 1)\n - `databus_imp_date` STRING — partition field\n - `instance_uuid` STRING — instance unique identifier\n - `host_gpu_num` DOUBLE — host GPU card count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification timestamp\n - `gpu_name` STRING — GPU model\n\n- `internal_platform_db.scan_task_instance_prestosql_007` (scan task instance GPU configuration table 2)\n - `databus_imp_date` STRING — partition field\n - `instance_uuid` STRING — instance unique identifier\n - `host_gpu_num` DOUBLE — host GPU card count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification timestamp\n - `gpu_name` STRING — GPU model\n - `scan_type` STRING — scan type\n\n**Computation Logic**:\n1. Filter specified metrics from the GPU monitoring data, and compute runtime per Pod in 5-minute time windows\n2. Join with the Pod-to-instance mapping to aggregate the GPU runtime and Pod count per instance per 5-minute window\n3. Retrieve the latest GPU configuration information for each task instance\n4. Compute the GPU card-hours (GPU-hour) per instance per 5-minute window\n5. The specific time window bucketing method, join conditions, aggregation logic, and GPU-hour computation formula must be determined based on the table structures and business semantics\n\n**Output Requirements**:\n- Target table: `internal_platform_db.t_scan_instance_gpu_time_stats_cand_prestosql_007`\n- Output fields and order: `instance_uuid` STRING, `time_5min` BIGINT, `host_gpu_num` DOUBLE, `sum_run_time_m` DOUBLE, `gpu_hour` DOUBLE, `gpu_name` STRING, `pod_count` BIGINT, `host_num` DOUBLE\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT INTO internal_platform_db.t_scan_instance_gpu_time_stats_prestosql_007\nWITH\n-- Step 1: From GPU monitoring data, extract pod run records with minute-level dedup\npod_run_minutes AS (\n SELECT\n pod_name,\n gpu_name,\n FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60 AS minute_timestamp,\n FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300 AS time_5min\n FROM internal_platform_db.t_gpu_monitor_parsed_prestosql_007\n WHERE dt = '2026060800'\n AND metric IN ('k8s_container_vgpu_gpu_mem_usage', 'k8s_dcgm_fi_dev_fb_util')\n GROUP BY pod_name, gpu_name, FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60, FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300\n),\n\n-- Step 2: Aggregate run minutes per pod per 5-minute window\npod_run_time AS (\n SELECT\n pod_name,\n MAX(gpu_name) AS gpu_name,\n time_5min,\n CAST(COUNT(DISTINCT minute_timestamp) AS DOUBLE) AS run_time_m\n FROM pod_run_minutes\n GROUP BY pod_name, time_5min\n),\n\n-- Step 3: Join pod-to-instance mapping, aggregate per instance per window\ninstance_run_time AS (\n SELECT\n p.time_5min,\n m.instance_uuid,\n MAX(p.gpu_name) AS gpu_name,\n CAST(SUM(p.run_time_m) AS DOUBLE) AS sum_run_time_m,\n COUNT(DISTINCT m.pod_name) AS pod_count\n FROM pod_run_time p\n INNER JOIN internal_platform_db.dwd_scan_instance_podname_prestosql_007 m\n ON p.pod_name = m.pod_name\n AND m.dt = '2026060800'\n GROUP BY p.time_5min, m.instance_uuid\n),\n\n-- Step 4: Get latest GPU config per instance from dual-table UNION ALL + ROW_NUMBER dedup\nlatest_task_config AS (\n SELECT\n instance_uuid,\n CAST(host_gpu_num AS DOUBLE) AS host_gpu_num,\n CAST(host_num AS DOUBLE) AS host_num,\n gpu_name\n FROM (\n SELECT\n instance_uuid,\n host_gpu_num,\n host_num,\n gpu_name,\n last_modify,\n ROW_NUMBER() OVER (PARTITION BY instance_uuid ORDER BY last_modify DESC) AS rn\n FROM (\n SELECT\n instance_uuid,\n host_gpu_num,\n host_num,\n gpu_name,\n last_modify\n FROM internal_platform_db.dwd_scan_task_instance_prestosql_007\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.dwd_scan_task_instance_prestosql_007\n )\n\n UNION ALL\n\n SELECT\n instance_uuid,\n host_gpu_num,\n host_num,\n gpu_name,\n last_modify\n FROM internal_platform_db.scan_task_instance_prestosql_007\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.scan_task_instance_prestosql_007\n )\n ) combined\n ) ranked\n WHERE rn = 1\n)\n\n-- Step 5: Join instance run time with GPU config, compute GPU-hour\nSELECT\n i.instance_uuid,\n i.time_5min,\n t.host_gpu_num,\n i.sum_run_time_m,\n CASE\n WHEN t.host_gpu_num IS NOT NULL AND i.sum_run_time_m IS NOT NULL\n THEN t.host_gpu_num * i.sum_run_time_m / 60.0\n ELSE NULL\n END AS gpu_hour,\n i.gpu_name,\n i.pod_count,\n t.host_num\nFROM instance_run_time i\nLEFT JOIN latest_task_config t\n ON i.instance_uuid = t.instance_uuid\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_007_en"} |
| {"task_id": "prestosql_008_en", "id": "offline-compute_PrestoSQL_prestosql_008", "name": "Report WUID Detail Filtering", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: From the ad report WUID detail wide table, filter target ad delivery records based on multi-dimensional filter conditions, extract key fields, and write the results to the output table.\n\n**Input Table**:\n- `internal_platform_db.t_report_wuid_detail_d_prestosql_008` (report WUID detail table)\n - `wuid` STRING — user identifier\n - `product_id` STRING — product ID\n - `adgroup_id` BIGINT — ad group ID\n - `action_time` BIGINT — action time\n - `crm_id` BIGINT — CRM ID\n - `creative_id` BIGINT — creative ID\n - `ocpx_conversion_cnt` BIGINT — oCpx conversion count\n - `optimization_goal` INT — optimization goal\n - `second_optimization_goal` INT — second-level optimization goal\n - `roi_goal` INT — ROI goal\n - `product_type` INT — product type\n - `site_set` INT — site set\n - `crm_advertiser_industry_id` BIGINT — CRM advertiser industry ID\n - `label` INT — label\n - `partition_time` BIGINT — partition time\n - `ds` BIGINT — partition field\n\n**Filter Conditions**:\n- `partition_time = 20260608`\n- `ocpx_conversion_cnt = 0`\n- `optimization_goal IN (105, 603)`\n- `second_optimization_goal = 0`\n- `roi_goal = 7`\n- `product_type = 46`\n- `site_set = 21`\n- `product_id IS NOT NULL`\n- `crm_advertiser_industry_id != 0`\n- `creative_id != 0`\n\n**Output Requirements**:\n- Target table: `internal_platform_db.sdk_sample_pay_neg_mini_cand_prestosql_008`\n- Output fields and order: `wuid` STRING, `product_id` STRING, `adgroup_id` BIGINT, `action_time` BIGINT, `crm_id` BIGINT, `creative_id` BIGINT, `label` INT, `product_type` INT, `optimization_goal` INT, `roi_goal` INT, `partition_time` BIGINT\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.sdk_sample_pay_neg_mini_prestosql_008\nSELECT\n wuid,\n product_id,\n adgroup_id,\n action_time,\n crm_id,\n creative_id,\n label,\n product_type,\n optimization_goal,\n roi_goal,\n partition_time\nFROM internal_platform_db.t_report_wuid_detail_d_prestosql_008\nWHERE partition_time = 20260608\n AND ocpx_conversion_cnt = 0\n AND optimization_goal IN (105, 603)\n AND second_optimization_goal = 0\n AND roi_goal = 7\n AND product_type = 46\n AND site_set = 21\n AND product_id IS NOT NULL\n AND crm_advertiser_industry_id != 0\n AND creative_id != 0", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_008_en"} |
| {"task_id": "prestosql_009", "id": "offline-compute_PrestoSQL_prestosql_009", "name": "Data Pipeline Killed Instance Analysis", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\nJoin pipeline span info and resource info tables to produce killed instance detail table. Specific filtering conditions and field selection need to be determined based on table structure.\n\n**输入表**:\n- `internal_platform_db.t_pipeline_span_info_prestosql_009`(Pipeline span信息表)\n - `databus_imp_date` STRING — 日期分区\n - `trace_id` STRING — 链路标识\n - `span_name` STRING — span名称\n - `start_time` STRING — 开始时间(epoch毫秒)\n - `end_time` STRING — 结束时间(epoch毫秒)\n - `status_code` INT — 状态码\n - `project_id` STRING — 项目ID\n - `task_id` STRING — 任务ID\n - `compute_type` STRING — 计算类型\n\n- `internal_platform_db.t_pipeline_resource_info_prestosql_009`(Pipeline资源信息表)\n - `databus_imp_date` STRING — 日期分区\n - `trace_id` STRING — 链路标识\n - `compute_type` STRING — 计算类型\n - `resource_id` STRING — 资源ID\n - `is_dedicated` STRING — 是否独占\n - `cpu_cores` INT — CPU核数\n\n**输出要求**:\n- 目标表: `internal_platform_db.t_pipeline_killed_instance_detail_cand_prestosql_009`\n- 具体过滤条件、字段选择、计算逻辑需根据表结构和数据特征自行分析确定\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT INTO internal_platform_db.t_pipeline_killed_instance_detail_prestosql_009\nWITH base_trace AS (\n SELECT trace_id\n FROM internal_platform_db.t_pipeline_span_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n AND span_name IN ('pipeline.execute', 'pipeline.killed')\n GROUP BY trace_id\n HAVING\n COUNT(CASE WHEN span_name = 'pipeline.killed' THEN 1 END) > 0\n AND\n COUNT(CASE WHEN span_name = 'pipeline.execute' THEN 1 END) = 0\n),\ncombined_spans AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n project_id,\n task_id,\n compute_type,\n status_code\n FROM internal_platform_db.t_pipeline_span_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('pipeline.killed', 'pipeline.start', 'task.run', 'task.compile', 'resource.request')\n\n UNION ALL\n\n SELECT\n trace_id,\n 'pipeline.execute' AS span_name,\n MAX(CASE WHEN span_name = 'pipeline.start' THEN start_time END) AS start_time,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN end_time END) AS end_time,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN project_id END) AS project_id,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN task_id END) AS task_id,\n MAX(CASE WHEN span_name = 'pipeline.killed' THEN compute_type END) AS compute_type,\n 2 AS status_code\n FROM internal_platform_db.t_pipeline_span_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('pipeline.start', 'pipeline.killed')\n GROUP BY trace_id\n),\nbase_data_time_fixed AS (\n SELECT\n trace_id,\n span_name,\n CASE\n WHEN span_name = 'pipeline.killed'\n THEN MIN(CASE WHEN span_name IN ('task.run', 'pipeline.killed') THEN start_time END)\n OVER(PARTITION BY trace_id)\n ELSE start_time\n END AS start_time,\n end_time,\n project_id,\n task_id,\n compute_type,\n status_code\n FROM combined_spans\n),\nbase_data AS (\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n project_id,\n task_id,\n compute_type,\n status_code,\n from_unixtime(CAST(start_time AS BIGINT) / 1000) AS start_date,\n from_unixtime(CAST(end_time AS BIGINT) / 1000) AS end_date,\n date_diff('day', CAST(from_unixtime(CAST(start_time AS BIGINT) / 1000) AS TIMESTAMP), CAST(from_unixtime(CAST(end_time AS BIGINT) / 1000) AS TIMESTAMP)) AS diff_days\n FROM base_data_time_fixed\n),\npos_series AS (\n SELECT 0 AS pos UNION ALL SELECT 1 AS pos UNION ALL SELECT 2 AS pos UNION ALL SELECT 3 AS pos\n),\ndaily_split_spans AS (\n SELECT\n trace_id,\n span_name,\n project_id,\n task_id,\n compute_type,\n status_code,\n start_date,\n end_date,\n diff_days,\n CAST(date_add('day', s.pos, CAST(b.start_date AS TIMESTAMP)) AS VARCHAR) AS calc_date,\n CASE WHEN s.pos = 0 THEN b.start_time\n ELSE CAST(CAST(to_unixtime(CAST(date_add('day', s.pos, CAST(b.start_date AS TIMESTAMP)) AS TIMESTAMP)) AS BIGINT) * 1000 AS VARCHAR)\n END AS start_time,\n CASE WHEN s.pos = b.diff_days THEN b.end_time\n ELSE CAST(CAST(to_unixtime(CAST(date_add('day', s.pos + 1, CAST(b.start_date AS TIMESTAMP)) AS TIMESTAMP)) AS BIGINT) * 1000 - 1 AS VARCHAR)\n END AS end_time,\n b.start_time AS span_start_time,\n b.end_time AS span_end_time\n FROM base_data b\n INNER JOIN pos_series s ON s.pos <= b.diff_days\n),\ntrace_time_metrics AS (\n SELECT\n trace_id,\n calc_date,\n MAX(project_id) AS project_id,\n MAX(task_id) AS task_id,\n MAX(compute_type) AS compute_type,\n MAX(MAX(CASE WHEN span_name = 'pipeline.execute' THEN status_code END)) OVER(PARTITION BY trace_id) AS status_code,\n CAST(ROUND((MAX(CASE WHEN span_name = 'pipeline.execute' THEN CAST(end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name = 'pipeline.execute' THEN CAST(start_time AS BIGINT) END)) / 1000.0) AS INT) AS instance_run_time,\n CAST(ROUND((MAX(CASE WHEN span_name IN ('task.run', 'task.compile', 'pipeline.killed') THEN CAST(end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name IN ('task.run', 'task.compile', 'pipeline.killed') THEN CAST(start_time AS BIGINT) END)) / 1000.0) AS INT) AS code_run_time,\n CAST(ROUND((MAX(CASE WHEN span_name = 'resource.request' THEN CAST(end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name = 'resource.request' THEN CAST(start_time AS BIGINT) END)) / 1000.0) AS INT) AS resource_wait_time\n FROM daily_split_spans\n GROUP BY trace_id, calc_date\n)\nSELECT\n t1.calc_date AS p_date,\n t1.trace_id,\n t1.project_id,\n t1.task_id,\n t1.compute_type,\n t1.status_code,\n t1.instance_run_time,\n t1.code_run_time,\n t1.resource_wait_time,\n t2.resource_id,\n CAST(t2.is_dedicated AS BOOLEAN) AS is_dedicated\nFROM trace_time_metrics t1 LEFT JOIN (\n SELECT\n trace_id,\n MAX(resource_id) AS resource_id,\n MAX(is_dedicated) AS is_dedicated\n FROM internal_platform_db.t_pipeline_resource_info_prestosql_009\n WHERE databus_imp_date = '20260608'\n GROUP BY trace_id\n) t2 ON t1.trace_id = t2.trace_id\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_009"} |
| {"task_id": "prestosql_010", "id": "offline-compute_PrestoSQL_prestosql_010", "name": "IOC MTTD指标计算", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:从API指标表和威胁情报IOC表中,通过JSON解析提取IOC值,与IOC表关联计算MTTD(平均检测时间)指标,写入输出表。\n\n**输入表**:\n- `internal_platform_db.t_app_ti_entity_api_metrics_prod_hi_prestosql_010`(API指标表)\n - `timestamp` BIGINT — 时间戳\n - `username` STRING — 用户名\n - `appid` BIGINT — 应用ID\n - `path` STRING — 路径\n - `request` STRING — 请求体(JSON)\n - `response` STRING — 响应体\n - `ds` BIGINT — 分区字段\n\n- `internal_platform_db.t_sh_threat_intel_lab_breakingti_soc_endpoint_security_format_output_prod_prestosql_010`(威胁情报IOC表)\n - `ioctype` STRING — IOC类型\n - `ioc` STRING — IOC值\n - `port` STRING — 端口\n - `producer` STRING — 生产者\n - `stamp` STRING — 时间戳\n - `category` STRING — 分类\n - `family` STRING — 家族\n - `apt_org` STRING — APT组织\n - `weapon` STRING — 武器\n - `usefor` STRING — 用途\n - `ttps` STRING — TTPs\n - `confidence` INT — 置信度\n - `context` STRING — 上下文\n - `intelligence_investigation` STRING — 情报调查\n - `match_subdomains` INT — 匹配子域名\n - `bdelete` INT — 删除标记\n - `deleted_time` STRING — 删除时间\n - `first_occur_time` STRING — 首次出现时间\n - `last_occur_time` STRING — 最后出现时间\n - `ds` BIGINT — 分区字段\n\n**计算逻辑**:\n1. 从API指标表提取: json_extract_scalar(request, '$.entity_value') AS ioc_value, 按ioc_value分组取MIN(timestamp) AS earliest_timestamp, 过滤ds=20260608\n2. 从IOC表过滤: ioctype='DOMAIN' AND bdelete=0, 过滤ds=20260608\n3. JOIN条件: ioc = ioc_value\n4. time_diff_days = GREATEST(0, (unix_timestamp(first_occur_time) - earliest_timestamp) / 86400.0)\n\n**输出要求**:\n- 目标表: `internal_platform_db.t_app_breaking_ti_mttd_metric_cand_prestosql_010`\n- 输出字段及顺序: `IOC` STRING, `IOCTYPE` STRING, `PORT` STRING, `first_occur_time` STRING, `earliest_timestamp` BIGINT, `family` STRING, `match_subdomains` INT, `time_diff_days` DOUBLE, `ds` BIGINT\n- ds: 固定值 20260608\n- 注意Presto中用json_extract_scalar代替get_json_object,用to_unixtime代替unix_timestamp(需配合FROM_UNIXTIME相关的转换)\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.t_app_breaking_ti_mttd_metric_prestosql_010\nWITH api_metrics AS (\n SELECT\n get_json_object(request, '$.entity_value') AS ioc_value,\n MIN(`timestamp`) AS earliest_timestamp\n FROM internal_platform_db.t_app_ti_entity_api_metrics_prod_hi_prestosql_010\n WHERE ds = 20260608\n GROUP BY get_json_object(request, '$.entity_value')\n),\nfiltered_main AS (\n SELECT *\n FROM internal_platform_db.t_sh_threat_intel_lab_breakingti_soc_endpoint_security_format_output_prod_prestosql_010\n WHERE ioctype = 'DOMAIN' AND bdelete = 0 AND ds = 20260608\n)\nSELECT\n f.ioc AS IOC,\n f.ioctype AS IOCTYPE,\n f.port AS PORT,\n f.first_occur_time,\n a.earliest_timestamp,\n f.family,\n f.match_subdomains,\n GREATEST(0, (unix_timestamp(f.first_occur_time) - a.earliest_timestamp) / 86400.0) AS time_diff_days,\n 20260608 AS ds\nFROM filtered_main f\nJOIN api_metrics a ON f.ioc = a.ioc_value", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_010"} |
| {"task_id": "prestosql_011", "id": "offline-compute_PrestoSQL_prestosql_011", "name": "安全平台PG敏感接口2表UNION+聚合", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "zh", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**任务目标**:将两个安全平台PG敏感接口数据表合并,排除黑名单域名后,按日期、域名和接口路径聚合,将匹配规则名拼接为逗号分隔字符串,写入输出表。\n\n**输入表**:(2个表结构相同)\n- `internal_platform_db.internal_sec_radept_secpg_data_result2_prestosql_011`\n- `internal_platform_db.internal_sec_radept_secpg_data_result4_prestosql_011`\n\n各表字段:\n - `databus_imp_date` INT — 数据日期\n - `insert_time` STRING — 插入时间\n - `src_ip` STRING — 源IP\n - `employeename` STRING — 员工名\n - `http_host` STRING — 域名\n - `http_cgi` STRING — 接口路径\n - `http_param` STRING — 请求参数\n - `http_user_agent` STRING — 用户代理\n - `http_referer` STRING — 来源\n - `http_body` STRING — 请求体\n - `http_head` STRING — 请求头\n - `httpsrsp_body` STRING — 响应体\n - `httpsrsp_content_length` STRING — 响应内容长度\n - `https_method` STRING — HTTPS方法\n - `scan_group` STRING — 扫描组\n - `rule_name` STRING — 规则名\n - `match_string` STRING — 匹配字符串\n - `match_type` STRING — 匹配类型\n - `scan_comment` STRING — 扫描备注\n\n**过滤条件**:\n- `databus_imp_date = 20260608`\n- `http_host NOT IN ('api.im-platform.example.com', 'mp.im-platform.example.com', 'open.im-platform.example.com', 'wx.im.example.com', 'wx2.im.example.com', 'wx8.im.example.com', 'web.im-platform.example.com', 'login.im-platform.example.com', 'long.open.im-platform.example.com', 'ext.im.example.com', 'proxy.svc.example.com', 'resolver.svc.example.com', 'cloud.provider.example.com', 'console.cloud.provider.example.com', 'csec.cloud.provider.example.com')`\n\n**输出要求**:\n- 目标表: `internal_platform_db.secpg_sensitive_interface_cand_prestosql_011`\n- 输出字段及顺序: `databus_imp_date` INT, `http_host` STRING, `http_cgi` STRING, `con_con` STRING\n- con_con: listagg(rule_name, ',') 或 array_join(array_agg(DISTINCT rule_name), ',') 聚合规则名\n- 按 databus_imp_date, http_host, http_cgi 分组\n- 如果目标表不存在,请先建表再写入数据\n- 请使用Presto/Trino SQL语法,不要使用Hive/Spark SQL方言\n\n**环境与执行说明**:\n- Presto已启动,通过Hive catalog连接\n- 执行SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- 写出result.sql后,必须自己执行验证它能成功运行并产出正确数据", "ground_truth": "INSERT OVERWRITE TABLE internal_platform_db.secpg_sensitive_interface_prestosql_011\nSELECT\n databus_imp_date,\n http_host,\n http_cgi,\n concat_ws(',', collect_set(rule_name)) AS con_con\nFROM (\n SELECT databus_imp_date, http_host, http_cgi, rule_name\n FROM internal_platform_db.internal_sec_radept_secpg_data_result2_prestosql_011\n WHERE databus_imp_date = 20260608\n AND http_host NOT IN ('api.im-platform.example.com', 'mp.im-platform.example.com', 'open.im-platform.example.com', 'wx.im.example.com', 'wx2.im.example.com', 'wx8.im.example.com', 'web.im-platform.example.com', 'login.im-platform.example.com', 'long.open.im-platform.example.com', 'ext.im.example.com', 'proxy.svc.example.com', 'resolver.svc.example.com', 'cloud.provider.example.com', 'console.cloud.provider.example.com', 'csec.cloud.provider.example.com')\n UNION ALL\n SELECT databus_imp_date, http_host, http_cgi, rule_name\n FROM internal_platform_db.internal_sec_radept_secpg_data_result4_prestosql_011\n WHERE databus_imp_date = 20260608\n AND http_host NOT IN ('api.im-platform.example.com', 'mp.im-platform.example.com', 'open.im-platform.example.com', 'wx.im.example.com', 'wx2.im.example.com', 'wx8.im.example.com', 'web.im-platform.example.com', 'login.im-platform.example.com', 'long.open.im-platform.example.com', 'ext.im.example.com', 'proxy.svc.example.com', 'resolver.svc.example.com', 'cloud.provider.example.com', 'console.cloud.provider.example.com', 'csec.cloud.provider.example.com')\n) combined\nGROUP BY databus_imp_date, http_host, http_cgi", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_011"} |
| {"task_id": "prestosql_012_en", "id": "offline-compute_PrestoSQL_prestosql_012", "name": "Data Quality Check Pipeline Instance GPU Card-Hour Analysis", "workload": "offline-compute", "engine": "PrestoSQL", "category": "offline-compute/PrestoSQL", "language": "en", "modality": "pure-text", "timeout_seconds": 900, "prompt": "## Prompt\n**Task Objective**: Analyze the runtime of data quality check pipeline instances. For some abnormally terminated instances, their completion records need to be backfilled. Compute the runtime duration of each instance per date shard, and combined with GPU monitoring data, compute the GPU card-hour consumption, ultimately outputting a detail table.\n\n**Business Background**:\nThe data quality check pipeline produces various span records, including check.start, check.completed, check.aborted, data.scan, rule.evaluate, resource.allocate, etc. Some instances only record check.aborted without check.completed. For these instances, a synthetic check.completed record must be constructed based on their start and aborted times to correctly compute the runtime duration.\n\nGPU monitoring data is collected in 5-minute windows and must be mapped to instances via Pod names. Combined with the GPU count from the task configuration, the card-hours are computed (gpu_hour = host_gpu_num * total_run_minutes / 60.0).\n\n**Input Tables**:\n- `internal_platform_db.t_quality_check_span_prestosql_012` (quality check span table)\n - `databus_imp_date` STRING — data date\n - `trace_id` STRING — trace ID\n - `span_name` STRING — span name\n - `start_time` STRING — start time (epoch milliseconds)\n - `end_time` STRING — end time (epoch milliseconds)\n - `status_code` INT — status code\n - `project_id` STRING — project ID\n - `task_id` STRING — task ID\n - `check_type` STRING — check type\n\n- `internal_platform_db.t_quality_gpu_monitor_prestosql_012` (GPU monitoring table)\n - `pod_name` STRING — Pod name\n - `pkg_time` STRING — collection time (epoch seconds)\n - `gpu_name` STRING — GPU model\n - `metric` STRING — monitoring metric\n - `value` STRING — metric value\n - `dt` STRING — date partition\n\n- `internal_platform_db.dwd_quality_podname_prestosql_012` (Pod-to-instance mapping table)\n - `dt` STRING — date partition\n - `instance_uuid` STRING — instance UUID\n - `pod_name` STRING — Pod name\n - `pod_phase` STRING — Pod phase\n\n- `internal_platform_db.dwd_quality_task_config_prestosql_012` (task GPU configuration table 1)\n - `databus_imp_date` STRING — data date\n - `instance_uuid` STRING — instance UUID\n - `host_gpu_num` DOUBLE — GPU count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification time\n - `gpu_name` STRING — GPU model\n - `resource_id` STRING — resource ID\n - `is_dedicated` STRING — whether dedicated\n\n- `internal_platform_db.quality_task_config_prestosql_012` (task GPU configuration table 2)\n - `databus_imp_date` STRING — data date\n - `instance_uuid` STRING — instance UUID\n - `host_gpu_num` DOUBLE — GPU count\n - `host_num` DOUBLE — host count\n - `last_modify` DOUBLE — last modification time\n - `gpu_name` STRING — GPU model\n - `resource_id` STRING — resource ID\n - `is_dedicated` STRING — whether dedicated\n - `scan_type` STRING — scan type\n\n**Key Logic Notes**:\n1. Identify trace_ids that have only check.aborted without check.completed, and synthesize a check.completed record for them\n2. Spans running across days must be split by day, generating one record per day\n3. GPU monitoring data must be deduplicated by 5-minute windows to compute running minutes, and mapped to instances via Pod mapping\n4. The two GPU configuration tables must be combined with UNION ALL, then use ROW_NUMBER to take the latest configuration per instance\n5. gpu_hour = host_gpu_num * total_run_minutes / 60.0\n\n**Output Requirements**:\n- Target table: `internal_platform_db.t_quality_check_gpu_instance_detail_cand_prestosql_012`\n- Output fields: `p_date` STRING, `trace_id` STRING, `project_id` STRING, `task_id` STRING, `check_type` STRING, `status_code` INT, `instance_run_time` INT, `code_run_time` INT, `gpu_hour` DOUBLE, `resource_id` STRING, `is_dedicated` BOOLEAN\n- If the target table does not exist, first create the table, then write the data\n- Use Presto/Trino SQL syntax; do not use Hive/Spark SQL dialects\n\n**Environment and Execution Notes**:\n- Presto is running, connected via the Hive catalog\n- Execute SQL: `presto-cli --catalog hive --schema internal_platform_db -f /tmp_workspace/result.sql`\n- After writing `result.sql`, you must execute it yourself to verify that it runs successfully and produces correct data", "ground_truth": "INSERT INTO internal_platform_db.t_quality_check_gpu_instance_detail_prestosql_012\nWITH base_trace AS (\n -- Step 1: Find trace_ids with check.aborted but NOT check.completed (HAVING inverted condition)\n SELECT trace_id\n FROM internal_platform_db.t_quality_check_span_prestosql_012\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND span_name IN ('check.aborted', 'check.completed')\n GROUP BY trace_id\n HAVING COUNT(CASE WHEN span_name = 'check.aborted' THEN 1 END) > 0\n AND COUNT(CASE WHEN span_name = 'check.completed' THEN 1 END) = 0\n),\ncombined_spans AS (\n -- Step 2: All original spans for ALL traces + synthetic check.completed for aborted-only traces\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n status_code,\n project_id,\n task_id,\n check_type\n FROM internal_platform_db.t_quality_check_span_prestosql_012\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND span_name IN ('check.aborted', 'check.start', 'check.completed', 'data.scan', 'rule.evaluate', 'resource.allocate')\n\n UNION ALL\n\n SELECT\n trace_id,\n 'check.completed' AS span_name,\n MAX(CASE WHEN span_name = 'check.start' THEN start_time END) AS start_time,\n MAX(CASE WHEN span_name = 'check.aborted' THEN end_time END) AS end_time,\n 2 AS status_code,\n MAX(CASE WHEN span_name = 'check.aborted' THEN project_id END) AS project_id,\n MAX(CASE WHEN span_name = 'check.aborted' THEN task_id END) AS task_id,\n MAX(CASE WHEN span_name = 'check.aborted' THEN check_type END) AS check_type\n FROM internal_platform_db.t_quality_check_span_prestosql_012\n WHERE databus_imp_date >= '2026060600'\n AND databus_imp_date <= '2026060800'\n AND trace_id IN (SELECT trace_id FROM base_trace)\n AND span_name IN ('check.start', 'check.aborted')\n GROUP BY trace_id\n),\nbase_data_time_fixed AS (\n -- Step 3: Fix check.aborted start_time -> earliest of code-related spans\n SELECT\n trace_id,\n span_name,\n CASE\n WHEN span_name = 'check.aborted'\n THEN MIN(CASE WHEN span_name IN ('data.scan', 'rule.evaluate', 'check.aborted') THEN start_time END)\n OVER(PARTITION BY trace_id)\n ELSE start_time\n END AS start_time,\n end_time,\n status_code,\n project_id,\n task_id,\n check_type\n FROM combined_spans\n),\nbase_data AS (\n -- Step 4: Convert timestamps, compute diff_days for cross-day splitting\n SELECT\n trace_id,\n span_name,\n start_time,\n end_time,\n status_code,\n project_id,\n task_id,\n check_type,\n from_unixtime(CAST(start_time AS BIGINT) / 1000) AS start_date,\n from_unixtime(CAST(end_time AS BIGINT) / 1000) AS end_date,\n date_diff('day', from_unixtime(CAST(start_time AS BIGINT) / 1000),\n from_unixtime(CAST(end_time AS BIGINT) / 1000)) AS diff_days,\n CAST(CAST(start_time AS BIGINT) / 86400000 AS BIGINT) * 86400000 AS start_day_midnight_ms\n FROM base_data_time_fixed\n),\npos_series AS (\n -- Step 5: Position series for cross-day expansion\n SELECT 0 AS pos UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3\n),\ndaily_split_spans AS (\n -- Step 6: INNER JOIN with pos_series, compute boundary timestamps per day\n SELECT\n trace_id,\n span_name,\n project_id,\n task_id,\n check_type,\n status_code,\n start_date,\n end_date,\n diff_days,\n date_add('day', s.pos, start_date) AS calc_date,\n CASE WHEN s.pos = 0 THEN start_time\n ELSE CAST(start_day_midnight_ms + s.pos * 86400000 AS VARCHAR)\n END AS split_start_time,\n CASE WHEN s.pos = diff_days THEN end_time\n ELSE CAST(start_day_midnight_ms + (s.pos + 1) * 86400000 - 1 AS VARCHAR)\n END AS split_end_time,\n start_time AS span_start_time,\n end_time AS span_end_time\n FROM base_data b\n INNER JOIN pos_series s ON s.pos <= b.diff_days\n),\nspan_metrics AS (\n -- Step 7: GROUP BY trace_id, calc_date -> compute instance_run_time, code_run_time, status_code\n SELECT\n trace_id,\n calc_date,\n MAX(project_id) AS project_id,\n MAX(task_id) AS task_id,\n MAX(check_type) AS check_type,\n MAX(MAX(CASE WHEN span_name = 'check.completed' THEN status_code END))\n OVER(PARTITION BY trace_id) AS status_code,\n CAST(ROUND(\n (MAX(CASE WHEN span_name = 'check.completed' THEN CAST(split_end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name = 'check.completed' THEN CAST(split_start_time AS BIGINT) END)) / 1000.0\n ) AS INT) AS instance_run_time,\n CAST(ROUND(\n (MAX(CASE WHEN span_name IN ('data.scan', 'rule.evaluate', 'check.aborted') THEN CAST(split_end_time AS BIGINT) END) -\n MIN(CASE WHEN span_name IN ('data.scan', 'rule.evaluate', 'check.aborted') THEN CAST(split_start_time AS BIGINT) END)) / 1000.0\n ) AS INT) AS code_run_time\n FROM daily_split_spans\n GROUP BY trace_id, calc_date\n),\ngpu_stats AS (\n -- Step 8: FLOOR 5-min window bucketing + pod mapping + ROW_NUMBER config dedup + gpu_hour\n SELECT\n ig.instance_uuid,\n lc.host_gpu_num * ig.total_run_time_m / 60.0 AS gpu_hour,\n ig.gpu_name,\n lc.resource_id,\n CASE WHEN lc.is_dedicated = 'true' THEN true ELSE false END AS is_dedicated\n FROM (\n -- Aggregate GPU run time per instance\n SELECT\n m.instance_uuid,\n MAX(p.gpu_name) AS gpu_name,\n SUM(p.run_time_m) AS total_run_time_m\n FROM (\n -- pod_run_time: count distinct minutes per (pod_name, time_5min)\n SELECT\n pod_name,\n MAX(gpu_name) AS gpu_name,\n time_5min,\n CAST(COUNT(DISTINCT minute_timestamp) AS DOUBLE) AS run_time_m\n FROM (\n -- pod_run_minutes: FLOOR bucketing dedup\n SELECT\n pod_name,\n gpu_name,\n FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60 AS minute_timestamp,\n FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300 AS time_5min\n FROM internal_platform_db.t_quality_gpu_monitor_prestosql_012\n WHERE metric IN ('k8s_container_vgpu_gpu_mem_usage', 'k8s_dcgm_fi_dev_fb_util')\n GROUP BY pod_name, gpu_name,\n FLOOR(CAST(pkg_time AS BIGINT) / 60) * 60,\n FLOOR(CAST(pkg_time AS BIGINT) / 300) * 300\n ) pod_run_minutes\n GROUP BY pod_name, time_5min\n ) p\n INNER JOIN internal_platform_db.dwd_quality_podname_prestosql_012 m\n ON p.pod_name = m.pod_name\n GROUP BY m.instance_uuid\n ) ig\n LEFT JOIN (\n -- latest_task_config: ROW_NUMBER dedup from UNION ALL of two config tables\n SELECT\n instance_uuid,\n host_gpu_num,\n resource_id,\n is_dedicated\n FROM (\n SELECT\n instance_uuid,\n host_gpu_num,\n resource_id,\n is_dedicated,\n ROW_NUMBER() OVER (PARTITION BY instance_uuid ORDER BY last_modify DESC) AS rn\n FROM (\n SELECT instance_uuid, host_gpu_num, last_modify, resource_id, is_dedicated\n FROM internal_platform_db.dwd_quality_task_config_prestosql_012\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.dwd_quality_task_config_prestosql_012\n )\n UNION ALL\n SELECT instance_uuid, host_gpu_num, last_modify, resource_id, is_dedicated\n FROM internal_platform_db.quality_task_config_prestosql_012\n WHERE databus_imp_date = (\n SELECT MAX(databus_imp_date)\n FROM internal_platform_db.quality_task_config_prestosql_012\n )\n ) combined\n ) ranked\n WHERE rn = 1\n ) lc ON ig.instance_uuid = lc.instance_uuid\n)\n-- Final: JOIN span_metrics with gpu_stats\nSELECT\n date_format(sm.calc_date, '%Y-%m-%d') AS p_date,\n sm.trace_id,\n sm.project_id,\n sm.task_id,\n sm.check_type,\n sm.status_code,\n sm.instance_run_time,\n sm.code_run_time,\n gs.gpu_hour,\n gs.resource_id,\n gs.is_dedicated\nFROM span_metrics sm\nLEFT JOIN gpu_stats gs ON sm.trace_id = gs.instance_uuid\n;", "expected_csv": "", "grade_spec_csv": "", "path": "tasks/offline-compute/PrestoSQL/prestosql_012_en"} |
|
|