-- Drop old tables from previous design DROP TABLE IF EXISTS internal_platform_db.dwd_game_user_receive_action_detail_data_di_prestosql_009; DROP TABLE IF EXISTS internal_platform_db.dwd_game_user_data_use_action_detail_data_di_prestosql_009; DROP TABLE IF EXISTS internal_platform_db.dwd_game_user_emao_find_action_detail_data_di_prestosql_009; DROP TABLE IF EXISTS internal_platform_db.dwd_game_user_social_action_detail_data_di_prestosql_009; DROP TABLE IF EXISTS internal_platform_db.dwd_game_user_contend_action_detail_data_di_prestosql_009; DROP TABLE IF EXISTS internal_platform_db.t_user_session_boundary_prestosql_009; DROP TABLE IF EXISTS internal_platform_db.dwd_game_user_action_detail_data_di_prestosql_009; DROP TABLE IF EXISTS internal_platform_db.dwd_game_user_action_detail_data_di_cand_prestosql_009; CREATE DATABASE IF NOT EXISTS internal_platform_db; -- Input table 1: Pipeline span info CREATE TABLE IF NOT EXISTS internal_platform_db.t_pipeline_span_info_prestosql_009 ( databus_imp_date STRING, trace_id STRING, span_name STRING, start_time STRING, end_time STRING, status_code INT, project_id STRING, task_id STRING, compute_type STRING ) STORED AS ORC; -- Mock data for pipeline span info -- T001: pipeline.killed + pipeline.start + task.run + resource.request, NO pipeline.execute -- Cross-day: starts 2026-06-07 22:00, ends 2026-06-08 02:00 (4 hours, crosses midnight) INSERT INTO TABLE internal_platform_db.t_pipeline_span_info_prestosql_009 VALUES -- T001 spans (killed, no execute) ('20260608', 'T001', 'pipeline.killed', '1749333600000', '1749348000000', 2, 'P001', 'TASK001', 'spark'), ('20260608', 'T001', 'pipeline.start', '1749333600000', '1749333900000', 0, 'P001', 'TASK001', 'spark'), ('20260608', 'T001', 'task.run', '1749334200000', '1749346800000', 0, 'P001', 'TASK001', 'spark'), ('20260608', 'T001', 'resource.request', '1749333600000', '1749333900000', 0, 'P001', 'TASK001', 'spark'), -- T002 spans (has execute, not killed - should be excluded from result) ('20260608', 'T002', 'pipeline.execute', '1749340800000', '1749348000000', 0, 'P002', 'TASK002', 'ray'), ('20260608', 'T002', 'pipeline.start', '1749340800000', '1749341100000', 0, 'P002', 'TASK002', 'ray'), ('20260608', 'T002', 'task.run', '1749341400000', '1749346800000', 0, 'P002', 'TASK002', 'ray'), -- T003 spans (killed, no execute, crosses 2 midnights) ('20260608', 'T003', 'pipeline.killed', '1749240000000', '1749355200000', 2, 'P003', 'TASK003', 'spark'), ('20260608', 'T003', 'pipeline.start', '1749240000000', '1749240300000', 0, 'P003', 'TASK003', 'spark'), ('20260608', 'T003', 'task.run', '1749240600000', '1749354600000', 0, 'P003', 'TASK003', 'spark'), ('20260608', 'T003', 'task.compile', '1749240300000', '1749240600000', 0, 'P003', 'TASK003', 'spark'), ('20260608', 'T003', 'resource.request', '1749240000000', '1749240300000', 0, 'P003', 'TASK003', 'spark'), -- T004 spans (has execute, not killed - should be excluded from result) ('20260608', 'T004', 'pipeline.execute', '1749340800000', '1749348000000', 0, 'P004', 'TASK004', 'ray'), ('20260608', 'T004', 'pipeline.start', '1749340800000', '1749341100000', 0, 'P004', 'TASK004', 'ray'), ('20260608', 'T004', 'task.compile', '1749341400000', '1749343200000', 0, 'P004', 'TASK004', 'ray'); -- Input table 2: Pipeline resource info CREATE TABLE IF NOT EXISTS internal_platform_db.t_pipeline_resource_info_prestosql_009 ( databus_imp_date STRING, trace_id STRING, compute_type STRING, resource_id STRING, is_dedicated STRING, cpu_cores INT ) STORED AS ORC; INSERT INTO TABLE internal_platform_db.t_pipeline_resource_info_prestosql_009 VALUES ('20260608', 'T001', 'spark', 'RES001', 'true', 8), ('20260608', 'T002', 'ray', 'RES002', 'false', 4), ('20260608', 'T003', 'spark', 'RES003', 'true', 16), ('20260608', 'T004', 'ray', 'RES004', 'false', 2); -- GT output table CREATE TABLE IF NOT EXISTS internal_platform_db.t_pipeline_killed_instance_detail_prestosql_009 ( p_date STRING, trace_id STRING, project_id STRING, task_id STRING, compute_type STRING, status_code INT, instance_run_time INT, code_run_time INT, resource_wait_time INT, resource_id STRING, is_dedicated BOOLEAN ) STORED AS ORC; -- Candidate output table CREATE TABLE IF NOT EXISTS internal_platform_db.t_pipeline_killed_instance_detail_cand_prestosql_009 ( p_date STRING, trace_id STRING, project_id STRING, task_id STRING, compute_type STRING, status_code INT, instance_run_time INT, code_run_time INT, resource_wait_time INT, resource_id STRING, is_dedicated BOOLEAN ) STORED AS ORC;