File size: 7,923 Bytes
e8c001c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
-- Drop old tables from previous design
DROP TABLE IF EXISTS internal_platform_db.t_ad_realtime_rpm_total_prestosql_012;
DROP TABLE IF EXISTS internal_platform_db.t_quality_event_prestosql_012;
DROP TABLE IF EXISTS internal_platform_db.t_ad_realtime_rpm_prestosql_012;
DROP TABLE IF EXISTS internal_platform_db.t_ad_realtime_rpm_cand_prestosql_012;

CREATE DATABASE IF NOT EXISTS internal_platform_db;

-- ============================================================
-- Input table 1: Quality check span info
-- T001: check.aborted NO check.completed, cross-day (Jun7 22:00 -> Jun8 01:00)
-- T002: check.completed, same day (Jun7 10:00 -> 11:30)
-- T003: check.aborted NO check.completed, cross-day (Jun6 20:00 -> Jun8 02:00, 3 days)
-- Base epoch: 2026-06-06 00:00:00 UTC = 1780694400
-- 2026-06-07 00:00:00 UTC = 1780780800
-- 2026-06-08 00:00:00 UTC = 1780867200
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.t_quality_check_span_prestosql_012 (
  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,
  check_type STRING
) STORED AS ORC;

INSERT INTO TABLE internal_platform_db.t_quality_check_span_prestosql_012 VALUES
-- T001: aborted without completed, cross-day Jun7 22:00 -> Jun8 01:00
('2026060800', 'T001', 'check.aborted',       '1780860600000', '1780870800000', 2, 'QP001', 'QT001', 'full'),
('2026060800', 'T001', 'check.start',          '1780860000000', '1780860060000', 0, 'QP001', 'QT001', 'full'),
('2026060800', 'T001', 'data.scan',            '1780860060000', '1780860600000', 0, 'QP001', 'QT001', 'full'),
('2026060800', 'T001', 'resource.allocate',    '1780856700000', '1780860000000', 0, 'QP001', 'QT001', 'full'),
-- T002: completed normally, same day Jun7 10:00 -> 11:30
('2026060700', 'T002', 'check.completed',      '1780816800000', '1780822200000', 0, 'QP002', 'QT002', 'incremental'),
('2026060700', 'T002', 'check.start',          '1780816800000', '1780816860000', 0, 'QP002', 'QT002', 'incremental'),
('2026060700', 'T002', 'data.scan',            '1780816860000', '1780818600000', 0, 'QP002', 'QT002', 'incremental'),
('2026060700', 'T002', 'rule.evaluate',        '1780818600000', '1780820400000', 0, 'QP002', 'QT002', 'incremental'),
-- T003: aborted without completed, cross-day Jun6 20:00 -> Jun8 02:00 (3 days)
('2026060800', 'T003', 'check.aborted',       '1780770000000', '1780874400000', 2, 'QP003', 'QT003', 'full'),
('2026060800', 'T003', 'check.start',          '1780766400000', '1780766460000', 0, 'QP003', 'QT003', 'full'),
('2026060800', 'T003', 'data.scan',            '1780766460000', '1780768200000', 0, 'QP003', 'QT003', 'full'),
('2026060800', 'T003', 'rule.evaluate',        '1780768200000', '1780770000000', 0, 'QP003', 'QT003', 'full'),
('2026060800', 'T003', 'resource.allocate',    '1780765800000', '1780766400000', 0, 'QP003', 'QT003', 'full');

-- ============================================================
-- Input table 2: GPU monitoring data (FLOOR 5-min bucketing)
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.t_quality_gpu_monitor_prestosql_012 (
  pod_name STRING,
  pkg_time STRING,
  gpu_name STRING,
  metric STRING,
  value STRING,
  dt STRING
) STORED AS ORC;

INSERT INTO TABLE internal_platform_db.t_quality_gpu_monitor_prestosql_012 VALUES
-- pod-qual-001 -> T001, A100, 5 distinct minutes in one 5-min window
('pod-qual-001', '1780860000', 'A100', 'k8s_container_vgpu_gpu_mem_usage', '80.5', '2026060800'),
('pod-qual-001', '1780860060', 'A100', 'k8s_container_vgpu_gpu_mem_usage', '82.0', '2026060800'),
('pod-qual-001', '1780860120', 'A100', 'k8s_container_vgpu_gpu_mem_usage', '78.0', '2026060800'),
('pod-qual-001', '1780860180', 'A100', 'k8s_dcgm_fi_dev_fb_util',        '65.0', '2026060800'),
('pod-qual-001', '1780860240', 'A100', 'k8s_dcgm_fi_dev_fb_util',        '68.0', '2026060800'),
-- pod-qual-003a -> T003, V100, 4 distinct minutes in one 5-min window
('pod-qual-003a', '1780766400', 'V100', 'k8s_container_vgpu_gpu_mem_usage', '90.0', '2026060800'),
('pod-qual-003a', '1780766460', 'V100', 'k8s_container_vgpu_gpu_mem_usage', '88.0', '2026060800'),
('pod-qual-003a', '1780766520', 'V100', 'k8s_dcgm_fi_dev_fb_util',        '70.0', '2026060800'),
('pod-qual-003a', '1780766580', 'V100', 'k8s_dcgm_fi_dev_fb_util',        '72.0', '2026060800'),
-- pod-qual-003b -> T003, V100, 2 distinct minutes in one 5-min window
('pod-qual-003b', '1780766400', 'V100', 'k8s_container_vgpu_gpu_mem_usage', '85.0', '2026060800'),
('pod-qual-003b', '1780766460', 'V100', 'k8s_container_vgpu_gpu_mem_usage', '83.0', '2026060800');

-- ============================================================
-- Input table 3: Pod-to-instance mapping
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.dwd_quality_podname_prestosql_012 (
  dt STRING,
  instance_uuid STRING,
  pod_name STRING,
  pod_phase STRING
) STORED AS ORC;

INSERT INTO TABLE internal_platform_db.dwd_quality_podname_prestosql_012 VALUES
('2026060800', 'T001', 'pod-qual-001',  'Running'),
('2026060800', 'T003', 'pod-qual-003a', 'Running'),
('2026060800', 'T003', 'pod-qual-003b', 'Running');

-- ============================================================
-- Input table 4: Task GPU config (source 1 for UNION ALL)
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.dwd_quality_task_config_prestosql_012 (
  databus_imp_date STRING,
  instance_uuid STRING,
  host_gpu_num DOUBLE,
  host_num DOUBLE,
  last_modify DOUBLE,
  gpu_name STRING,
  resource_id STRING,
  is_dedicated STRING
) STORED AS ORC;

INSERT INTO TABLE internal_platform_db.dwd_quality_task_config_prestosql_012 VALUES
-- T001: later last_modify than quality_task_config entry -> wins ROW_NUMBER dedup
('2026060800', 'T001', 8.0, 2.0, 1780765801.0, 'A100', 'RES001', 'true');

-- ============================================================
-- Input table 5: Additional task config (source 2 for UNION ALL)
-- Has extra scan_type column
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.quality_task_config_prestosql_012 (
  databus_imp_date STRING,
  instance_uuid STRING,
  host_gpu_num DOUBLE,
  host_num DOUBLE,
  last_modify DOUBLE,
  gpu_name STRING,
  resource_id STRING,
  is_dedicated STRING,
  scan_type STRING
) STORED AS ORC;

INSERT INTO TABLE internal_platform_db.quality_task_config_prestosql_012 VALUES
-- T003: only source for this instance
('2026060800', 'T003', 4.0, 1.0, 1780765800.0, 'V100', 'RES003', 'false', 'full'),
-- T001: earlier last_modify than dwd entry -> loses ROW_NUMBER dedup
('2026060800', 'T001', 6.0, 1.0, 1780765800.0, 'A100', 'RES001_ALT', 'false', 'incremental');

-- ============================================================
-- GT output table
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.t_quality_check_gpu_instance_detail_prestosql_012 (
  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
) STORED AS ORC;

-- ============================================================
-- Candidate output table
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.t_quality_check_gpu_instance_detail_cand_prestosql_012 (
  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
) STORED AS ORC;