-
Notifications
You must be signed in to change notification settings - Fork 0
/
Glue job script.txt
71 lines (54 loc) · 2.31 KB
/
Glue job script.txt
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
select DISTINCT `driverid`,`driverslicensestate` from myDataSource
select DISTINCT `pedestrianid`,`pedestriantype` from myDataSource
select DISTINCT `vehicleid`,`vehiclemake`,`vehiclemodel`,`vehicleyear`,`vehiclebodytype`from myDataSource
select DISTINCT `crossstreetname`,`weather`,`light`,`speedlimit` from myDataSource
select DISTINCT `reportNumber`,`driverid`,`vehicleid`,`pedestrianid`,`crossstreetname`,`crashdate`,`agencyname`,`localcasenumber`,`acrsreporttype`,`collisiontype`,`trafficcontrol`,`driversubstanceabuse`,`nonmotoristsubstanceabuse`,`driversinjuryseverity`,`speedlimit`,`pedestriansinjuryseverity` from myDataSource
-- create database final_project1;
use final_project1;
CREATE TABLE PedestrianDim (
pedestrianid VARCHAR(255) PRIMARY KEY,
pedestriantype VARCHAR(250)-- Assuming it's boolean-like field represented as 'Yes' or 'No'
);
CREATE TABLE VehicleDim (
vehicleid VARCHAR(255) PRIMARY KEY,
vehiclemake VARCHAR(250),
vehiclemodel VARCHAR(250),
vehicleyear INT,
vehiclebodytype VARCHAR(250)
);
CREATE TABLE LocationDim (
crashdate date,
latitude DECIMAL(10, 10),
longitude DECIMAL(10, 10),
weather VARCHAR(255),
light VARCHAR(255),
crossstreetname varchar(100),
speedlimit int,
PRIMARY KEY (crossstreetname, crashdate)
);
CREATE TABLE DriverDim (
driverid VARCHAR(255) PRIMARY KEY,
driverslicensestate VARCHAR(250)
);
CREATE TABLE CrashFact (
reportNumber VARCHAR(255) PRIMARY KEY,
driverid VARCHAR(255),
vehicleid VARCHAR(255),
pedestrianid VARCHAR(255),
crossstreetname varchar(100),
crashdate date,
agencyname VARCHAR(255),
localcasenumber varchar(250), -- Assuming it's numeric
acrsreporttype VARCHAR(255),
collisiontype VARCHAR(255),
trafficcontrol VARCHAR(255),
driversubstanceabuse varchar(250),
nonmotoristsubstanceabuse varchar(250),
driversinjuryseverity varchar(250),
speedlimit int,
pedestriansinjuryseverity varchar(250),
FOREIGN KEY (driverid) REFERENCES DriverDim(driverid),
FOREIGN KEY (vehicleid) REFERENCES VehicleDim(vehicleid),
FOREIGN KEY (pedestrianid) REFERENCES PedestrianDim(pedestrianid),
FOREIGN KEY (crossstreetname, crashdate) REFERENCES LocationDim(crossstreetname, crashdate)
);