dicemy's picture
Upload 655 files
e8c001c verified
Raw
History Blame Contribute Delete
7.97 kB
-- 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;