| |
| """pyspark_016 database initialization: create tables + load seed data""" |
| from pyspark.sql import SparkSession |
|
|
| spark = SparkSession.builder \ |
| .appName('dataclaw_eval_init_pyspark_016') \ |
| .enableHiveSupport() \ |
| .config('spark.sql.warehouse.dir', '/tmp/hive_warehouse') \ |
| .getOrCreate() |
|
|
| spark.sql('CREATE DATABASE IF NOT EXISTS internal_platform_db') |
|
|
| |
| spark.sql(''' |
| CREATE TABLE IF NOT EXISTS internal_platform_db.dim_org_framework_org_d_f_pyspark_220 ( |
| `org_id` BIGINT, |
| `org_name` STRING, |
| `type_id` BIGINT, |
| `type_name` STRING, |
| `type_dw` STRING, |
| `org_path` STRING, |
| `org_full_path` STRING, |
| `parent_id` BIGINT, |
| `company_id` BIGINT, |
| `company_name` STRING, |
| `org_bg_01_id` BIGINT, |
| `org_bg_01_name` STRING, |
| `org_bg_02_id` BIGINT, |
| `org_bg_02_name` STRING, |
| `business_line_01_id` BIGINT, |
| `business_line_01_name` STRING, |
| `business_line_02_id` BIGINT, |
| `business_line_02_name` STRING, |
| `department_01_id` BIGINT, |
| `department_01_name` STRING, |
| `department_02_id` BIGINT, |
| `department_02_name` STRING, |
| `department_03_id` BIGINT, |
| `department_03_name` STRING, |
| `department_04_id` BIGINT, |
| `department_04_name` STRING, |
| `center_01_id` BIGINT, |
| `center_01_name` STRING, |
| `center_02_id` BIGINT, |
| `center_02_name` STRING, |
| `center_03_id` BIGINT, |
| `center_03_name` STRING, |
| `group_01_id` BIGINT, |
| `group_01_name` STRING, |
| `group_02_id` BIGINT, |
| `group_02_name` STRING, |
| `group_03_id` BIGINT, |
| `group_03_name` STRING, |
| `group_04_id` BIGINT, |
| `group_04_name` STRING, |
| `group_05_id` BIGINT, |
| `group_05_name` STRING, |
| `group_06_id` BIGINT, |
| `group_06_name` STRING, |
| `group_07_id` BIGINT, |
| `group_07_name` STRING, |
| `group_08_id` BIGINT, |
| `group_08_name` STRING, |
| `is_enabled` BIGINT, |
| `is_deleted` BIGINT, |
| `is_virtual` BIGINT, |
| `year` STRING, |
| `month` STRING, |
| `day` STRING |
| ) STORED AS ORC |
| ''') |
|
|
| spark.sql(''' |
| INSERT INTO internal_platform_db.dim_org_framework_org_d_f_pyspark_220 VALUES |
| (100, 'CompanyA', 1, 'company', 'cp', '/100', '/100', 0, 100, 'CompanyA', 200, 'BG1', -1, '', 300, 'BL1', -1, '', 400, 'Dept1', -1, '', -1, '', -1, '', 500, 'Center1', -1, '', -1, '', 600, 'Group1', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', 1, 0, 0, '2026', '05', '13'), |
| (400, 'Dept1', 2, 'department', 'dp', '/100/400', '/100/200/300/400', 300, 100, 'CompanyA', 200, 'BG1', -1, '', 300, 'BL1', -1, '', 400, 'Dept1', -1, '', -1, '', -1, '', 500, 'Center1', -1, '', -1, '', 600, 'Group1', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', 1, 0, 0, '2026', '05', '13'), |
| (500, 'Center1', 3, 'center', 'ct', '/100/500', '/100/200/300/400/500', 400, 100, 'CompanyA', 200, 'BG1', -1, '', 300, 'BL1', -1, '', 400, 'Dept1', -1, '', -1, '', -1, '', 500, 'Center1', -1, '', -1, '', 600, 'Group1', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', 1, 0, 0, '2026', '05', '13'), |
| (600, 'Group1', 4, 'group', 'gp', '/100/600', '/100/200/300/400/500/600', 500, 100, 'CompanyA', 200, 'BG1', -1, '', 300, 'BL1', -1, '', 400, 'Dept1', -1, '', -1, '', -1, '', 500, 'Center1', -1, '', -1, '', 600, 'Group1', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', -1, '', 1, 0, 0, '2026', '05', '13') |
| ''') |
|
|
| |
| spark.sql(''' |
| CREATE TABLE IF NOT EXISTS internal_platform_db.dim_code_employee_user_org_relation_bare_d_f_pyspark_220 ( |
| `org_id` BIGINT, |
| `org_type_id` BIGINT, |
| `company_id` BIGINT, |
| `company_name` STRING, |
| `org_bg_id` BIGINT, |
| `org_bg_name` STRING, |
| `business_line_id` BIGINT, |
| `business_line_name` STRING, |
| `department_id` BIGINT, |
| `department_name` STRING, |
| `center_id` BIGINT, |
| `center_name` STRING, |
| `group_id` BIGINT, |
| `group_name` STRING, |
| `employee_id` BIGINT, |
| `user_id` BIGINT, |
| `user_name` STRING, |
| `employee_type_id` BIGINT, |
| `year` STRING, |
| `month` STRING, |
| `day` STRING |
| ) STORED AS ORC |
| ''') |
|
|
| spark.sql(''' |
| INSERT INTO internal_platform_db.dim_code_employee_user_org_relation_bare_d_f_pyspark_220 VALUES |
| (600, 4, 100, 'CompanyA', 200, 'BG1', 300, 'BL1', 400, 'Dept1', 500, 'Center1', 600, 'Group1', 1001, 1001, 'alice', 1, '2026', '05', '13'), |
| (600, 4, 100, 'CompanyA', 200, 'BG1', 300, 'BL1', 400, 'Dept1', 500, 'Center1', 600, 'Group1', 1002, 1002, 'bob', 1, '2026', '05', '13'), |
| (600, 4, 100, 'CompanyA', 200, 'BG1', 300, 'BL1', 400, 'Dept1', 500, 'Center1', 600, 'Group1', 1003, 1003, 'charlie', 1, '2026', '05', '13') |
| ''') |
|
|
| |
| spark.sql(''' |
| CREATE TABLE IF NOT EXISTS internal_platform_db.dual_pyspark_220 ( |
| `dummy` STRING |
| ) STORED AS ORC |
| ''') |
|
|
| spark.sql("INSERT INTO internal_platform_db.dual_pyspark_220 VALUES ('X')") |
|
|
| |
| spark.sql(''' |
| CREATE TABLE IF NOT EXISTS internal_platform_db.dwm_code_review_note_user_stat_d_f_pyspark_220 ( |
| `note_crt_date` DATE, |
| `project_id` BIGINT, |
| `author_id` BIGINT, |
| `author_name` STRING, |
| `line_human_note_cnt` BIGINT, |
| `line_system_note_cnt` BIGINT, |
| `global_human_note_cnt` BIGINT, |
| `global_system_note_cnt` BIGINT, |
| `total` BIGINT, |
| `created_at` TIMESTAMP, |
| `updated_at` TIMESTAMP, |
| `year` STRING, |
| `month` STRING, |
| `day` STRING |
| ) STORED AS ORC |
| ''') |
|
|
| spark.sql(''' |
| INSERT INTO internal_platform_db.dwm_code_review_note_user_stat_d_f_pyspark_220 VALUES |
| (CAST('2026-05-10' AS DATE), 1, 1001, 'alice', 50, 10, 5, 2, 67, CAST('2026-05-10 10:00:00' AS TIMESTAMP), CAST('2026-05-10 10:00:00' AS TIMESTAMP), '2026', '05', '13'), |
| (CAST('2026-05-08' AS DATE), 2, 1002, 'bob', 30, 5, 3, 1, 39, CAST('2026-05-08 10:00:00' AS TIMESTAMP), CAST('2026-05-08 10:00:00' AS TIMESTAMP), '2026', '05', '13'), |
| (CAST('2026-05-05' AS DATE), 3, 1003, 'charlie', 20, 3, 2, 0, 25, CAST('2026-05-05 10:00:00' AS TIMESTAMP), CAST('2026-05-05 10:00:00' AS TIMESTAMP), '2026', '05', '13') |
| ''') |
|
|
| |
| spark.sql(''' |
| CREATE TABLE IF NOT EXISTS internal_platform_db.dwd_code_review_used_time_d_i_pyspark_220 ( |
| `dt` STRING, |
| `ori_id` BIGINT, |
| `review_id` BIGINT, |
| `project_id` BIGINT, |
| `reviewer_id` BIGINT, |
| `reviewer_name` STRING, |
| `created_at` STRING, |
| `updated_at` STRING, |
| `duration_total` BIGINT, |
| `duration_today` BIGINT, |
| `is_review_author` BIGINT, |
| `is_reviewer` BIGINT, |
| `is_fileowner` BIGINT, |
| `year` STRING, |
| `month` STRING, |
| `day` STRING |
| ) STORED AS ORC |
| ''') |
|
|
| spark.sql(''' |
| INSERT INTO internal_platform_db.dwd_code_review_used_time_d_i_pyspark_220 VALUES |
| ('2026-05-10', 1, 101, 1, 1001, 'alice', '2026-05-10 09:00:00', '2026-05-10 10:00:00', 3600, 120, 0, 1, 0, '2026', '05', '10'), |
| ('2026-05-11', 2, 102, 2, 1002, 'bob', '2026-05-11 09:00:00', '2026-05-11 10:00:00', 7200, 200, 0, 1, 0, '2026', '05', '11'), |
| ('2026-05-12', 3, 103, 3, 1003, 'charlie', '2026-05-12 09:00:00', '2026-05-12 10:00:00', 5400, 80, 0, 0, 1, '2026', '05', '12') |
| ''') |
|
|
| print('Database initialization complete') |
| spark.stop() |
|
|