dicemy's picture
Upload 655 files
e8c001c verified
Raw
History Blame Contribute Delete
6.27 kB
-- Drop old tables from previous design
DROP TABLE IF EXISTS internal_platform_db.t_app_urlsafe_cont_pending_tobe_send_list_hi_prestosql_001;
DROP TABLE IF EXISTS internal_platform_db.t_risk_event_prestosql_001;
DROP TABLE IF EXISTS internal_platform_db.t_dws_urlsafe_cont_domain_list_monitor_prestosql_001;
DROP TABLE IF EXISTS internal_platform_db.t_dws_urlsafe_cont_domain_list_monitor_cand_prestosql_001;
CREATE DATABASE IF NOT EXISTS internal_platform_db;
-- Input table 1: security scan spans
CREATE TABLE IF NOT EXISTS internal_platform_db.t_security_scan_span_prestosql_001 (
databus_imp_date STRING COMMENT 'partition date',
trace_id STRING COMMENT 'trace ID',
span_name STRING COMMENT 'span name: scan.start, scan.execute, scan.completed, scan.failed, scan.cleanup, resource.allocate',
start_time STRING COMMENT 'epoch milliseconds',
end_time STRING COMMENT 'epoch milliseconds',
status_code INT COMMENT '0=ok, 2=failed',
security_project_id STRING COMMENT 'security project ID',
security_task_id STRING COMMENT 'security task ID',
scan_type STRING COMMENT 'scan type: full, incremental'
) STORED AS ORC;
-- Mock data for scan spans
-- Epoch base: 2026-06-06 00:00:00 UTC = 1780704000000 ms, each day = 86400000 ms
-- T001: has scan.failed but NO scan.completed -> qualifies for synthetic row fabrication
-- Cross-day: starts 2026-06-07, ends 2026-06-08
-- Spans: scan.failed, scan.start, scan.execute, resource.allocate
INSERT INTO TABLE internal_platform_db.t_security_scan_span_prestosql_001 VALUES
('2026060700', 'T001', 'scan.failed', '1780882200000', '1780882205000', 2, 'SEC_P001', 'SEC_T001', 'full'),
('2026060700', 'T001', 'scan.start', '1780794000000', '1780794005000', 0, 'SEC_P001', 'SEC_T001', 'full'),
('2026060700', 'T001', 'scan.execute', '1780797600000', '1780882200000', 0, 'SEC_P001', 'SEC_T001', 'full'),
('2026060700', 'T001', 'resource.allocate', '1780792200000', '1780794000000', 0, 'SEC_P001', 'SEC_T001', 'full'),
-- T002: has both scan.completed AND scan.failed -> does NOT qualify
-- Same day: 2026-06-07
('2026060700', 'T002', 'scan.completed', '1780807200000', '1780807203000', 0, 'SEC_P002', 'SEC_T002', 'incremental'),
('2026060700', 'T002', 'scan.execute', '1780805400000', '1780807200000', 0, 'SEC_P002', 'SEC_T002', 'incremental'),
('2026060700', 'T002', 'scan.start', '1780804800000', '1780804803000', 0, 'SEC_P002', 'SEC_T002', 'incremental'),
('2026060700', 'T002', 'scan.failed', '1780807800000', '1780807805000', 2, 'SEC_P002', 'SEC_T002', 'incremental'),
-- T003: has scan.failed but NO scan.completed -> qualifies
-- Cross-day: starts 2026-06-06, ends 2026-06-08 (3 days)
-- Spans: scan.failed, scan.start, scan.execute, scan.cleanup, resource.allocate
('2026060600', 'T003', 'scan.failed', '1780885800000', '1780885805000', 2, 'SEC_P003', 'SEC_T003', 'full'),
('2026060600', 'T003', 'scan.start', '1780707600000', '1780707605000', 0, 'SEC_P003', 'SEC_T003', 'full'),
('2026060600', 'T003', 'scan.execute', '1780711200000', '1780885800000', 0, 'SEC_P003', 'SEC_T003', 'full'),
('2026060600', 'T003', 'scan.cleanup', '1780885805000', '1780886105000', 0, 'SEC_P003', 'SEC_T003', 'full'),
('2026060600', 'T003', 'resource.allocate', '1780705800000', '1780707600000', 0, 'SEC_P003', 'SEC_T003', 'full'),
-- T004: normal trace with scan.completed only, same day
('2026060700', 'T004', 'scan.completed', '1780810800000', '1780810803000', 0, 'SEC_P004', 'SEC_T004', 'incremental'),
('2026060700', 'T004', 'scan.execute', '1780809000000', '1780810800000', 0, 'SEC_P004', 'SEC_T004', 'incremental'),
('2026060700', 'T004', 'scan.start', '1780808400000', '1780808403000', 0, 'SEC_P004', 'SEC_T004', 'incremental');
-- Input table 2: resource allocation info
CREATE TABLE IF NOT EXISTS internal_platform_db.t_security_resource_info_prestosql_001 (
databus_imp_date STRING COMMENT 'partition date',
trace_id STRING COMMENT 'trace ID',
scan_type STRING COMMENT 'scan type: full, incremental',
resource_id STRING COMMENT 'resource ID',
is_dedicated STRING COMMENT 'true or false',
cpu_cores INT COMMENT 'CPU cores allocated',
gpu_count INT COMMENT 'GPU count allocated'
) STORED AS ORC;
INSERT INTO TABLE internal_platform_db.t_security_resource_info_prestosql_001 VALUES
('2026060700', 'T001', 'full', 'RES_001', 'true', 8, 2),
('2026060700', 'T002', 'incremental', 'RES_002', 'false', 4, 0),
('2026060700', 'T003', 'full', 'RES_003', 'true', 16, 4),
('2026060700', 'T004', 'incremental', 'RES_004', 'false', 2, 0);
-- GT output table (NOT partitioned)
CREATE TABLE IF NOT EXISTS internal_platform_db.t_security_scan_instance_detail_prestosql_001 (
p_date STRING COMMENT 'calc date',
trace_id STRING COMMENT 'trace ID',
security_project_id STRING COMMENT 'security project ID',
security_task_id STRING COMMENT 'security task ID',
scan_type STRING COMMENT 'scan type',
status_code INT COMMENT 'status code',
scan_run_time INT COMMENT 'scan execution time in seconds',
code_run_time INT COMMENT 'code run time in seconds',
resource_wait_time INT COMMENT 'resource wait time in seconds',
resource_id STRING COMMENT 'resource ID',
is_dedicated BOOLEAN COMMENT 'is dedicated resource',
apply_for_cpu_count INT COMMENT 'CPU cores applied'
) STORED AS ORC;
-- Candidate output table (same structure with _cand_ in name)
CREATE TABLE IF NOT EXISTS internal_platform_db.t_security_scan_instance_detail_cand_prestosql_001 (
p_date STRING COMMENT 'calc date',
trace_id STRING COMMENT 'trace ID',
security_project_id STRING COMMENT 'security project ID',
security_task_id STRING COMMENT 'security task ID',
scan_type STRING COMMENT 'scan type',
status_code INT COMMENT 'status code',
scan_run_time INT COMMENT 'scan execution time in seconds',
code_run_time INT COMMENT 'code run time in seconds',
resource_wait_time INT COMMENT 'resource wait time in seconds',
resource_id STRING COMMENT 'resource ID',
is_dedicated BOOLEAN COMMENT 'is dedicated resource',
apply_for_cpu_count INT COMMENT 'CPU cores applied'
) STORED AS ORC;