File size: 7,090 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python3
"""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')

# Create dim_org_framework_org_d_f table
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')
''')

# Create dim_code_employee_user_org_relation_bare_d_f table
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')
''')

# Create dual table
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')")

# Create dwm_code_review_note_user_stat_d_f table
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')
''')

# Create dwd_code_review_used_time_d_i table
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()