--- id: offline-compute_HiveSQL_hivesql_003 name: 从 `internal_platform_db.notebook_span_info_query_engine category: offline-compute/HiveSQL timeout_seconds: 600 modality: pure-text engine: hivesql --- ## Prompt 1) 任务目标 识别并统计 Notebook 管道中被异常 kill 且缺失正常完成信号的 Ray 实例,按天拆分计算运行时长、代码执行时长、资源等待时长及 GPU 申请数。 2) 输入 - `internal_platform_db.notebook_span_info_query_engine_007` - `internal_platform_db.notebook_engine_info_query_engine_007` 3) 处理规则 - 目标实例筛选:从 span_info 筛选 `compute_type='ray'` 且 `service_name='notebook-runner'` 的实例,选取有 `span_name='runner.killed'` 但无 `span_name='runner.execute'` 的 `trace_id`。 - 合成运行区间:对每个目标 trace_id,取 `span_name='runner.start'` 的 start_time 作为实例开始时间,取 `span_name='runner.killed'` 的 end_time 作为实例结束时间,合成 `runner.execute` 区间,`status_code` 固定为 2。 - 跨天拆分:将合成区间按自然日拆分为多条记录,每条对应一天内的部分,`calc_date` 为拆分后的日期。 - 时长计算(按 trace_id 与 calc_date): - instance_run_time:合成区间在当天的起止时间差(毫秒转秒)。 - code_run_time:`span_name` 为 'execute.code', 'execute.code.cell', 'client.execute.code', 'runner.killed' 在当天的起止时间差(毫秒转秒)。 - resource_wait_time:`span_name` 为 'set.permanent.compute', 'create.non.permanent.compute' 在当天的起止时间差(毫秒转秒)。 - 输出 code_start_time/code_end_time/instance_start_time/instance_end_time(时间戳转字符串)。 - 关联引擎信息:左关联 engine_info(过滤 `compute_type='ray'` 且 `service_name='notebook-runner'`),关联键 `trace_id`,获取 serving_id、is_permanent,计算 `apply_for_gpu_count = SUM(replicas * num_gpu)`。 4) 输出要求 输出字段顺序:dt(STRING,分区)、p_date(STRING,calc_date)、trace_id(STRING)、datawd_project_id(STRING)、datawd_task_id(STRING)、datawd_task_instance_id(STRING)、compute_type(STRING)、status_code(INT)、instance_run_time(INT)、code_run_time(INT)、resource_wait_time(INT)、code_start_time(STRING)、code_end_time(STRING)、instance_start_time(STRING)、instance_end_time(STRING)、serving_id(STRING)、is_permanent(BOOLEAN)、apply_for_gpu_count(INT)。 5) 写入要求 目标表:`internal_platform_db.dwd_notebook_killed_instance_detail_d_copilot_cand_query_engine_007`。分区字段:dt。写入分区:`dt='20260507'`。写入模式:覆盖。 请将最终 HiveSQL 写入 result.sql 并执行。