File size: 7,969 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
-- Drop old tables from previous design
DROP TABLE IF EXISTS internal_platform_db.t_app_apksafe_cont_res_detect_center_stat_di_prestosql_007;
DROP TABLE IF EXISTS internal_platform_db.t_threat_event_prestosql_007;
DROP TABLE IF EXISTS internal_platform_db.t_md_apksafe_res_detect_center_stat_prestosql_007;
DROP TABLE IF EXISTS internal_platform_db.t_md_apksafe_res_detect_center_stat_cand_prestosql_007;

CREATE DATABASE IF NOT EXISTS internal_platform_db;

-- ============================================================
-- Input table 1: GPU monitoring data (parsed metrics from containers)
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.t_gpu_monitor_parsed_prestosql_007 (
  container STRING,
  pod_name STRING,
  pkg_time STRING,
  gpu_name STRING,
  metric STRING,
  value STRING,
  dt STRING
) STORED AS ORC;

-- Epoch base: 2026-06-08 00:00:00 UTC = 1749331200
-- Using relative offsets from that base for clarity
-- 5-min windows: 0-299, 300-599, 600-899, etc.
-- pod_scan_apk_a1: 4 timestamps across 2 windows, 2 metrics each
-- pod_scan_apk_a2: 3 timestamps in 1 window, 2 metrics each
-- pod_scan_apk_b1: 3 timestamps across 2 windows, 2 metrics each
-- pod_scan_apk_b2: 2 timestamps in 1 window, 2 metrics each

INSERT INTO TABLE internal_platform_db.t_gpu_monitor_parsed_prestosql_007 VALUES
-- pod_scan_apk_a1: metric='k8s_container_vgpu_gpu_mem_usage'
('ctr_a1_0', 'pod_scan_apk_a1', '1749331230', 'GPU-A100', 'k8s_container_vgpu_gpu_mem_usage', '0.65', '2026060800'),
('ctr_a1_0', 'pod_scan_apk_a1', '1749331290', 'GPU-A100', 'k8s_container_vgpu_gpu_mem_usage', '0.70', '2026060800'),
('ctr_a1_0', 'pod_scan_apk_a1', '1749331350', 'GPU-A100', 'k8s_container_vgpu_gpu_mem_usage', '0.72', '2026060800'),
('ctr_a1_0', 'pod_scan_apk_a1', '1749331530', 'GPU-A100', 'k8s_container_vgpu_gpu_mem_usage', '0.68', '2026060800'),
-- pod_scan_apk_a1: metric='k8s_dcgm_fi_dev_fb_util'
('ctr_a1_1', 'pod_scan_apk_a1', '1749331230', 'GPU-A100', 'k8s_dcgm_fi_dev_fb_util', '45.2', '2026060800'),
('ctr_a1_1', 'pod_scan_apk_a1', '1749331290', 'GPU-A100', 'k8s_dcgm_fi_dev_fb_util', '48.1', '2026060800'),
('ctr_a1_1', 'pod_scan_apk_a1', '1749331350', 'GPU-A100', 'k8s_dcgm_fi_dev_fb_util', '50.3', '2026060800'),
('ctr_a1_1', 'pod_scan_apk_a1', '1749331530', 'GPU-A100', 'k8s_dcgm_fi_dev_fb_util', '46.7', '2026060800'),
-- pod_scan_apk_a2: metric='k8s_container_vgpu_gpu_mem_usage'
('ctr_a2_0', 'pod_scan_apk_a2', '1749331245', 'GPU-A100', 'k8s_container_vgpu_gpu_mem_usage', '0.55', '2026060800'),
('ctr_a2_0', 'pod_scan_apk_a2', '1749331305', 'GPU-A100', 'k8s_container_vgpu_gpu_mem_usage', '0.58', '2026060800'),
('ctr_a2_0', 'pod_scan_apk_a2', '1749331365', 'GPU-A100', 'k8s_container_vgpu_gpu_mem_usage', '0.60', '2026060800'),
-- pod_scan_apk_a2: metric='k8s_dcgm_fi_dev_fb_util'
('ctr_a2_1', 'pod_scan_apk_a2', '1749331245', 'GPU-A100', 'k8s_dcgm_fi_dev_fb_util', '40.1', '2026060800'),
('ctr_a2_1', 'pod_scan_apk_a2', '1749331305', 'GPU-A100', 'k8s_dcgm_fi_dev_fb_util', '42.5', '2026060800'),
('ctr_a2_1', 'pod_scan_apk_a2', '1749331365', 'GPU-A100', 'k8s_dcgm_fi_dev_fb_util', '44.0', '2026060800'),
-- pod_scan_apk_b1: metric='k8s_container_vgpu_gpu_mem_usage'
('ctr_b1_0', 'pod_scan_apk_b1', '1749331260', 'GPU-V100', 'k8s_container_vgpu_gpu_mem_usage', '0.80', '2026060800'),
('ctr_b1_0', 'pod_scan_apk_b1', '1749331320', 'GPU-V100', 'k8s_container_vgpu_gpu_mem_usage', '0.82', '2026060800'),
('ctr_b1_0', 'pod_scan_apk_b1', '1749331560', 'GPU-V100', 'k8s_container_vgpu_gpu_mem_usage', '0.78', '2026060800'),
-- pod_scan_apk_b1: metric='k8s_dcgm_fi_dev_fb_util'
('ctr_b1_1', 'pod_scan_apk_b1', '1749331260', 'GPU-V100', 'k8s_dcgm_fi_dev_fb_util', '55.0', '2026060800'),
('ctr_b1_1', 'pod_scan_apk_b1', '1749331320', 'GPU-V100', 'k8s_dcgm_fi_dev_fb_util', '58.3', '2026060800'),
('ctr_b1_1', 'pod_scan_apk_b1', '1749331560', 'GPU-V100', 'k8s_dcgm_fi_dev_fb_util', '52.1', '2026060800'),
-- pod_scan_apk_b2: metric='k8s_container_vgpu_gpu_mem_usage'
('ctr_b2_0', 'pod_scan_apk_b2', '1749331275', 'GPU-V100', 'k8s_container_vgpu_gpu_mem_usage', '0.75', '2026060800'),
('ctr_b2_0', 'pod_scan_apk_b2', '1749331335', 'GPU-V100', 'k8s_container_vgpu_gpu_mem_usage', '0.77', '2026060800'),
-- pod_scan_apk_b2: metric='k8s_dcgm_fi_dev_fb_util'
('ctr_b2_1', 'pod_scan_apk_b2', '1749331275', 'GPU-V100', 'k8s_dcgm_fi_dev_fb_util', '50.8', '2026060800'),
('ctr_b2_1', 'pod_scan_apk_b2', '1749331335', 'GPU-V100', 'k8s_dcgm_fi_dev_fb_util', '53.2', '2026060800');

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

INSERT INTO TABLE internal_platform_db.dwd_scan_instance_podname_prestosql_007 VALUES
('2026060800', 'inst_apk_scan_001', 'pod_scan_apk_a1', 'Running', 'apk-threat-scan'),
('2026060800', 'inst_apk_scan_001', 'pod_scan_apk_a2', 'Running', 'apk-threat-scan'),
('2026060800', 'inst_apk_scan_002', 'pod_scan_apk_b1', 'Running', 'apk-threat-scan'),
('2026060800', 'inst_apk_scan_002', 'pod_scan_apk_b2', 'Running', 'apk-threat-scan');

-- ============================================================
-- Input table 3: Task instance GPU config (dwd - primary source)
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.dwd_scan_task_instance_prestosql_007 (
  databus_imp_date STRING,
  instance_uuid STRING,
  host_gpu_num DOUBLE,
  host_num DOUBLE,
  last_modify DOUBLE,
  gpu_name STRING
) STORED AS ORC;

-- inst_apk_scan_001: 2 rows with different last_modify (need ROW_NUMBER dedup)
-- inst_apk_scan_002: only appears here with older last_modify
INSERT INTO TABLE internal_platform_db.dwd_scan_task_instance_prestosql_007 VALUES
('2026060800', 'inst_apk_scan_001', 4.0, 2.0, 1717761600.0, 'GPU-A100'),
('2026060800', 'inst_apk_scan_001', 8.0, 4.0, 1717848000.0, 'GPU-A100'),
('2026060800', 'inst_apk_scan_002', 2.0, 1.0, 1717675200.0, 'GPU-V100');

-- ============================================================
-- Input table 4: Scan task instance config (secondary source, like hivesql_022's dual-table pattern)
-- ============================================================
CREATE TABLE IF NOT EXISTS internal_platform_db.scan_task_instance_prestosql_007 (
  databus_imp_date STRING,
  instance_uuid STRING,
  host_gpu_num DOUBLE,
  host_num DOUBLE,
  last_modify DOUBLE,
  gpu_name STRING,
  scan_type STRING
) STORED AS ORC;

-- inst_apk_scan_002: newer config here (will win ROW_NUMBER dedup)
-- inst_apk_scan_003: only exists in this table (extra instance for completeness)
INSERT INTO TABLE internal_platform_db.scan_task_instance_prestosql_007 VALUES
('2026060800', 'inst_apk_scan_002', 4.0, 2.0, 1717934400.0, 'GPU-V100', 'full_scan'),
('2026060800', 'inst_apk_scan_003', 8.0, 4.0, 1717934400.0, 'GPU-A100', 'quick_scan');

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

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