-
Notifications
You must be signed in to change notification settings - Fork 20
/
ddl_IMDB_ProjDimModel.sql
654 lines (507 loc) · 16.2 KB
/
ddl_IMDB_ProjDimModel.sql
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
-- use IMDB;
--- IMDb Movie Project
-- Rick Sherman
-- Modified: 2020-04-19 10:40am added directors
--use imdb_project
--go
-- Drop table
DROP TABLE IF EXISTS dim_imdb_name_basics ;
-- people involved in the titles
CREATE TABLE dim_imdb_name_basics (
name_sk int NOT NULL IDENTITY(1,1),
nconst varchar(10) NOT NULL,
primaryName varchar(255),
birthYear int,
deathYear int,
name_imdb_url varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY NONCLUSTERED (name_sk)
);
CREATE CLUSTERED INDEX CIX_dim_imdb_name_basics ON dim_imdb_name_basics (nconst);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_titleType;
CREATE TABLE dim_imdb_titleType (
titleType_sk int NOT NULL IDENTITY(1,1),
titleType varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (titleType_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_basics;
CREATE TABLE dim_imdb_title_basics (
title_sk int NOT NULL IDENTITY(1,1),
tconst varchar(10) NOT NULL,
titleType_sk int, -- new FK
movieId int null, -- MovieLens ID
imdbId varchar(20) null, -- imdbId from MovieLens ID
tmdbId int null, -- tmdbId from MovieLens ID
primaryTitle varchar(1024),
originalTitle varchar(1024),
ml_title varchar(255), -- MovieLens Title
isAdult bit,
startYear int,
endYear int,
runtimeMinutes int,
title_imdb_url varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY NONCLUSTERED (title_sk)
);
CREATE CLUSTERED INDEX CIX_dim_imdb_title_basics ON dim_imdb_title_basics (tconst);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_brand;
CREATE TABLE dim_imdb_brand (
Brand_sk int NOT NULL IDENTITY(1,1),
Brand_Name varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Brand_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_Franchise;
CREATE TABLE dim_imdb_Franchise (
Franchise_sk int NOT NULL IDENTITY(1,1),
Franchise_Name varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Franchise_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_primaryProfession;
CREATE TABLE dim_imdb_primaryProfession (
primaryProfession_sk int NOT NULL IDENTITY(1,1),
primaryProfession varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (primaryProfession_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_name_basics_knownForTitles;
CREATE TABLE dim_imdb_name_basics_knownForTitles (
knownForTitles_sk int NOT NULL IDENTITY(1,1),
name_sk int not null,
title_sk int not null, -- knownForTitles varchar(1024),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (knownForTitles_sk)
);
CREATE INDEX IDX_dim_imdb_name_basics_knownForTitles ON dim_imdb_name_basics_knownForTitles (name_sk, title_sk);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_name_basics_primaryProfession;
CREATE TABLE dim_imdb_name_basics_primaryProfession (
name_basics_primaryProfession_sk int NOT NULL IDENTITY(1,1),
name_sk int,
primaryProfession_sk int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (name_basics_primaryProfession_sk)
);
CREATE INDEX IDX_dim_imdb_name_basics_primaryProfession ON dim_imdb_name_basics_primaryProfession (name_sk,primaryProfession_sk);
-- Drop table
DROP TABLE IF EXISTS dim_iso_country;
CREATE TABLE dim_iso_country (
Country_SK int NOT NULL IDENTITY(1,1),
country_name varchar(255),
alpha_2 varchar(2),
alpha_3 varchar(3),
country_code int,
iso_3166_2 varchar(80),
region varchar(255),
sub_region varchar(255),
intermediate_region varchar(255),
region_code int,
sub_region_code int,
intermediate_region_code int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Country_SK)
);
-- Drop table
DROP TABLE IF EXISTS dim_iso_language;
CREATE TABLE dim_iso_language (
Language_SK int NOT NULL IDENTITY(1,1),
alpha3_b varchar(3),
alpha3_t varchar(3),
alpha2 varchar(2),
Language_Name varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Language_SK)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_akas ;
CREATE TABLE dim_imdb_title_akas (
title_akas_SK int NOT NULL IDENTITY(1,1),
title_sk int,
title_ordering int NOT NULL,
title_akas varchar(1024),
country_SK int null,
region varchar(255), -- fk
language_SK int null,
movie_language varchar(255), -- fk
title_akas_types varchar(255),
title_akas_attributes varchar(1024),
isOriginalTitle varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (title_akas_SK)
);
CREATE INDEX IDX_dim_imdb_title_akas ON dim_imdb_title_akas (title_sk);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_genres;
CREATE TABLE dim_imdb_genres (
genres_sk int NOT NULL IDENTITY(1,1),
genres varchar(255),
genre_source varchar(80), -- imdb or MovieLens
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (genres_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_basics_genres ;
CREATE TABLE dim_imdb_title_basics_genres (
titles_genres_sk int NOT NULL IDENTITY(1,1),
title_sk int,
genres_sk int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (titles_genres_sk)
);
CREATE INDEX IDX_SK_dim_imdb_title_basics_genres ON dim_imdb_title_basics_genres (title_sk,genres_sk);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_crew_directors;
CREATE TABLE dim_imdb_title_crew_directors (
directors_sk int NOT NULL IDENTITY(1,1),
title_sk int,
name_sk int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (directors_sk)
);
CREATE INDEX IDX_SK_dim_imdb_title_crew_directors ON dim_imdb_title_crew_directors (title_sk,name_sk);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_crew_writers ;
CREATE TABLE dim_imdb_title_crew_writers (
writers_sk int NOT NULL IDENTITY(1,1),
title_sk int,
name_sk int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (writers_sk)
);
CREATE INDEX IDX_SK_dim_imdb_title_crew_writers ON dim_imdb_title_crew_writers (title_sk,name_sk);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_episode ;
CREATE TABLE dim_imdb_title_episode (
title_episode_sk int NOT NULL IDENTITY(1,1),
title_sk int,
parent_title_sk int,
seasonNumber int,
episodeNumber int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (title_episode_sk)
);
CREATE INDEX IDX_SK_dim_imdb_title_episode ON dim_imdb_title_episode (title_sk,parent_title_sk);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_job_category;
CREATE TABLE dim_imdb_job_category (
job_category_sk int NOT NULL IDENTITY(1,1),
job_category varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (job_category_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_principals
CREATE TABLE dim_imdb_title_principals (
title_principals_sk int NOT NULL IDENTITY(1,1),
title_sk int not null,
name_sk int not null,
title_ordering int NOT NULL,
job_category_sk int,
job_title varchar(1024),
character_name varchar(1024),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (title_principals_sk) -- (tconst,[ordering])
);
CREATE UNIQUE INDEX UDX_SK_dim_imdb_title_principals ON dim_imdb_title_principals (title_sk,name_sk,title_ordering);
-- Drop table
DROP TABLE IF EXISTS fct_imdb_title_ratings ;
CREATE TABLE fct_imdb_title_ratings (
title_ratings_sk int NOT NULL IDENTITY(1,1),
title_sk int not null,
averageRating real,
numVotes int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (title_ratings_sk)
);
CREATE INDEX IDX_SK_fct_imdb_title_ratings ON fct_imdb_title_ratings (title_sk);
-- Drop table
DROP TABLE IF EXISTS fct_ml_genome_scores;
CREATE TABLE fct_ml_genome_scores (
genome_scores_sk int NOT NULL IDENTITY(1,1),
title_sk int not null,
tagId int NOT NULL,
relevance decimal (10,3),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY CLUSTERED (title_sk,tagId)
);
-- Drop tab
DROP TABLE IF EXISTS fct_ml_genome_tags ;
CREATE TABLE fct_ml_genome_tags (
tagId int NOT NULL, -- NK
tag varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (tagId)
);
-- Drop table
DROP TABLE IF EXISTS fct_ml_ratings ;
CREATE TABLE fct_ml_ratings (
title_sk int NOT NULL,
userId int NOT NULL,
rating decimal(10,3),
ratings_datetime datetime,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY CLUSTERED (title_sk,userId)
);
-- Drop table
DROP TABLE IF EXISTS fct_ml_tags ;
CREATE TABLE fct_ml_tags (
ml_tags_sk int NOT NULL IDENTITY(1,1),
title_sk int NOT NULL,
userId int NOT NULL,
tag varchar(255),
ratings_datetime datetime,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (ml_tags_sk)
);
-- Drop table
DROP TABLE IF EXISTS fct_numbers_daily_box_office ;
CREATE TABLE fct_numbers_daily_box_office (
daily_box_office_sk int NOT NULL IDENTITY(1,1),
title_sk int NOT NULL,
Show_Date datetime NOT NULL,
Daily_Rank int,
Daily_Gross bigint,
Daily_Change_Pct decimal(10,3),
Weekly_Change_Pct decimal(10,3),
Number_of_Theaters int,
Gross_Per_Theater bigint,
Total_Gross bigint,
Number_of_Days int,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (daily_box_office_sk)
);
-- Drop table
DROP TABLE IF EXISTS fct_numbers_franchise_all_box_office;
CREATE TABLE fct_numbers_franchise_all_box_office (
franchise_all_sk int NOT NULL IDENTITY(1,1),
franchise_sk int NOT NULL,
No_of_Movies int NOT NULL,
Domestic_Box_Office bigint NOT NULL,
Infl_Adj_Dom_Box_Office bigint NOT NULL,
Worldwide_Box_Office bigint NOT NULL,
First_Year int NOT NULL,
Last_Year int NOT NULL,
No_of_Years int NOT NULL,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (franchise_all_sk)
);
-- Drop table
DROP TABLE IF EXISTS fct_numbers_franchise_movies_box_office ;
CREATE TABLE fct_numbers_franchise_movies_box_office (
frachise_movies_box_office_sk int NOT NULL IDENTITY(1,1),
franchise_sk int NOT NULL,
Release_Date datetime NOT NULL,
title_sk int NOT NULL,
Production_Budget bigint,
Opening_Weekend bigint,
Domestic_Box_Office bigint,
Worldwide_Box_Office bigint,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (frachise_movies_box_office_sk)
);
-- Drop table
DROP TABLE IF EXISTS fct_imdb_brands_gross ;
CREATE TABLE fct_imdb_brands_gross (
Brands_Gross_SK int NOT NULL IDENTITY(1,1),
brand_sk int NOT NULL,
Total_Revenue bigint,
Number_of_Releases int,
Top_Release varchar(255),
Lifetime_Gross bigint,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Brands_Gross_SK)
);
-- Drop table
DROP TABLE IF EXISTS fct_imdb_brands_list;
CREATE TABLE fct_imdb_brands_list (
Brands_Lists_SK int NOT NULL IDENTITY(1,1),
brand_sk int NOT NULL,
release_Rank int,
title_sk int NOT NULL,
Lifetime_Gross bigint,
Max_Theaters int,
Opening_Gross bigint,
Open_Theaters int,
Release_Date datetime,
Distributor varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Brands_Lists_SK)
);
-- Drop table
DROP TABLE IF EXISTS fct_imdb_franchises_gross;
CREATE TABLE fct_imdb_franchises_gross (
Franchises_Gross_SK int NOT NULL IDENTITY(1,1),
franchise_sk int NOT NULL,
Total_Revenue bigint,
Number_of_Releases int,
Top_Release varchar(255),
Lifetime_Gross bigint,
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Franchises_Gross_SK)
);
-- Drop table
DROP TABLE IF EXISTS fct_imdb_franchises_list;
CREATE TABLE fct_imdb_franchises_list (
Franchises_Lists_SK int NOT NULL IDENTITY(1,1),
franchise_sk int NOT NULL,
Release_Rank int,
title_sk int NOT NULL,
Lifetime_Gross bigint,
Max_Theaters int,
Opening_Gross bigint,
Open_Theaters int,
Release_Date datetime,
Distributor varchar(255),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (Franchises_Lists_SK)
);
-- Drop table
DROP TABLE IF EXISTS fct_movies_box_office_worldwide;
-- top 100 movies by lifetime gross from IMDb
CREATE TABLE fct_movies_box_office_worldwide (
movies_box_office_worldwide_sk int NOT NULL IDENTITY(1,1),
title_sk int NOT NULL,
BoxOffice_Rank int,
Worldwide_LifetimeGross bigint,
Domestic_LifetimeGross bigint,
Domestic_Pct decimal(10,3), -- drop?
Foreign_LifetimeGross bigint,
Foreign_Pct decimal(10,3), -- drop?
Release_Year int, -- drop?
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (movies_box_office_worldwide_sk)
);
---------------------------------
---- Reject Tables
---------------------------------------------
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_principals_rejects;
CREATE TABLE dim_imdb_title_principals_rejects (
title_principals_sk int NOT NULL IDENTITY(1,1),
title_sk int null,
tconst varchar(10) null,
name_sk int null,
nconst varchar(10) null,
title_ordering int NULL,
job_category_sk int null,
job_category varchar(255),
job_title varchar(1024),
character_name varchar(1024),
reject_reason varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (title_principals_sk) -- (tconst,[ordering])
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_crew_directors_rejects;
CREATE TABLE dim_imdb_title_crew_directors_rejects (
directors_sk int NOT NULL IDENTITY(1,1),
title_sk int null,
tconst varchar(10) null,
name_sk int null,
nconst varchar(10) null,
reject_reason varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (directors_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_crew_writers_rejects ;
CREATE TABLE dim_imdb_title_crew_writers_rejects (
writers_sk int NOT NULL IDENTITY(1,1),
title_sk int null,
tconst varchar(10) null,
name_sk int null,
nconst varchar(10) null,
reject_reason varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (writers_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_name_basics_knownForTitles_rejects;
CREATE TABLE dim_imdb_name_basics_knownForTitles_rejects (
knownForTitles_sk int NOT NULL IDENTITY(1,1),
title_sk int null,
tconst varchar(10) null,
name_sk int null,
nconst varchar(10) null,
reject_reason varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (knownForTitles_sk)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_akas_rejects ;
CREATE TABLE dim_imdb_title_akas_rejects (
title_akas_SK int NOT NULL IDENTITY(1,1),
title_sk int null,
tconst varchar(10) null,
title_ordering int NOT NULL,
title_akas varchar(1024),
country_SK int null,
region varchar(255), -- fk
language_SK int null,
movie_language varchar(255), -- fk
title_akas_types varchar(255),
title_akas_attributes varchar(1024),
isOriginalTitle varchar(255),
reject_reason varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (title_akas_SK)
);
-- Drop table
DROP TABLE IF EXISTS dim_imdb_title_episode_rejects ; ;
CREATE TABLE dim_imdb_title_episode_rejects (
title_episode_sk int NOT NULL IDENTITY(1,1),
title_sk int,
parent_title_sk int,
tconst varchar(10) null ,
parentTconst varchar(10),
seasonNumber int,
episodeNumber int,
reject_reason varchar(80),
DI_JobID varchar(20) NOT NULL,
DI_Create_DT datetime DEFAULT getdate() NOT NULL,
PRIMARY KEY (title_episode_sk)
);