dicemy's picture
Upload 655 files
e8c001c verified
Raw
History Blame Contribute Delete
2.77 kB
-- mysql_015 database initialization: create tables + load seed data
-- Executed via: mysql -u root < init_db.sql
-- Fix: MySQL root default auth_socket blocks pymysql TCP connections,
-- switch to mysql_native_password so pymysql (Python) can connect.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root123';
FLUSH PRIVILEGES;
-- Ensure consistent timezone (Hive cluster was UTC+8)
SET GLOBAL time_zone = '+08:00';
SET SESSION time_zone = '+08:00';
CREATE DATABASE IF NOT EXISTS internal_platform_db
DEFAULT CHARACTER SET utf8mb4
DEFAULT COLLATE utf8mb4_unicode_ci;
USE internal_platform_db;
-- Input table: exposure log data (Hive STRUCT columns flattened to MySQL columns)
CREATE TABLE IF NOT EXISTS etl_pageview_exposure_mysql_015 (
partition_time BIGINT NOT NULL COMMENT '分区时间(YYYYMMDDHHmm)',
ad_aid BIGINT NOT NULL COMMENT '广告ID',
ad_data_model_version INT NOT NULL COMMENT '数据模型版本',
ad_optimization_goal INT NOT NULL COMMENT '优化目标',
action_imp_time BIGINT NOT NULL COMMENT '曝光时间(毫秒时间戳)',
PRIMARY KEY (partition_time, ad_aid, ad_data_model_version, ad_optimization_goal, action_imp_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Output table: first exposure time result
CREATE TABLE IF NOT EXISTS first_expo_time_cand_mysql_015 (
aid BIGINT NOT NULL COMMENT '广告ID',
first_time BIGINT NOT NULL COMMENT '首次曝光时间(毫秒时间戳)',
first_fen VARCHAR(32) NOT NULL COMMENT '首次曝光分钟(yyyyMMddHHmm)',
dt BIGINT NOT NULL COMMENT '分区时间(YYYYMMDDHHmm)',
PRIMARY KEY (aid, dt)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Seed data: 9 rows
-- Rows 1-4 pass filter (partition=2026060914, dmv=3, og>0), rows 5-9 filtered out
INSERT INTO etl_pageview_exposure_mysql_015
(partition_time, ad_aid, ad_data_model_version, ad_optimization_goal, action_imp_time)
VALUES
(2026060914, 1001, 3, 1, 1717938000000),
(2026060914, 1001, 3, 2, 1717941600000),
(2026060914, 1002, 3, 1, 1717938001000),
(2026060914, 1003, 3, 5, 1717945200000),
(2026060914, 1001, 2, 1, 1717930000000), -- filtered: ad_data_model_version=2 (smaller ts than 1001's min, leaks if dmv filter dropped)
(2026060914, 1004, 3, 0, 1717950000000), -- filtered: ad_optimization_goal=0
(2026050100, 1005, 3, 1, 1717950000000), -- filtered: wrong partition_time
(2026060913, 1001, 3, 1, 1717900000000), -- filtered: different partition (tests GROUP BY scope)
(2026060914, 1006, 3, -1, 1717960000000); -- filtered: negative ad_optimization_goal