-
Notifications
You must be signed in to change notification settings - Fork 0
/
Machine_Learning_Curated.py
151 lines (140 loc) · 4.96 KB
/
Machine_Learning_Curated.py
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
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
from awsglue.dynamicframe import DynamicFrame
from pyspark.sql import functions as SqlFuncs
args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)
# Script generated for node Accelerometer Trusted Zone
AccelerometerTrustedZone_node1688102900198 = (
glueContext.create_dynamic_frame.from_options(
format_options={"multiline": False},
connection_type="s3",
format="json",
connection_options={
"paths": ["s3://neidhpa-lakehouse-project/accelerometer_trusted/"],
"recurse": True,
},
transformation_ctx="AccelerometerTrustedZone_node1688102900198",
)
)
# Script generated for node Customer Trusted Zone
CustomerTrustedZone_node1688782334053 = glueContext.create_dynamic_frame.from_options(
format_options={"multiline": False},
connection_type="s3",
format="json",
connection_options={
"paths": ["s3://neidhpa-lakehouse-project/customer_trusted/"],
"recurse": True,
},
transformation_ctx="CustomerTrustedZone_node1688782334053",
)
# Script generated for node Step Trainer Trusted Zone
StepTrainerTrustedZone_node1 = glueContext.create_dynamic_frame.from_options(
format_options={"multiline": False},
connection_type="s3",
format="json",
connection_options={
"paths": ["s3://neidhpa-lakehouse-project/step_trainer_curated/"],
"recurse": True,
},
transformation_ctx="StepTrainerTrustedZone_node1",
)
# Script generated for node Renamed keys for Join
RenamedkeysforJoin_node1688782409638 = ApplyMapping.apply(
frame=CustomerTrustedZone_node1688782334053,
mappings=[
("serialNumber", "string", "customer_serialNumber", "string"),
(
"shareWithPublicAsOfDate",
"bigint",
"customer_shareWithPublicAsOfDate",
"long",
),
("birthDay", "string", "customer_birthDay", "string"),
("registrationDate", "bigint", "customer_registrationDate", "long"),
(
"shareWithResearchAsOfDate",
"bigint",
"customer_shareWithResearchAsOfDate",
"long",
),
("customerName", "string", "customer_customerName", "string"),
("email", "string", "customer_email", "string"),
("lastUpdateDate", "bigint", "customer_lastUpdateDate", "long"),
("phone", "string", "customer_phone", "string"),
(
"shareWithFriendsAsOfDate",
"bigint",
"customer_shareWithFriendsAsOfDate",
"long",
),
],
transformation_ctx="RenamedkeysforJoin_node1688782409638",
)
# Script generated for node Join
Join_node1688782324503 = Join.apply(
frame1=StepTrainerTrustedZone_node1,
frame2=RenamedkeysforJoin_node1688782409638,
keys1=["serialNumber"],
keys2=["customer_serialNumber"],
transformation_ctx="Join_node1688782324503",
)
# Script generated for node Drop Duplicates
DropDuplicates_node1688842698270 = DynamicFrame.fromDF(
Join_node1688782324503.toDF().dropDuplicates(),
glueContext,
"DropDuplicates_node1688842698270",
)
# Script generated for node Join Step Trainer
JoinStepTrainer_node1688103008151 = Join.apply(
frame1=AccelerometerTrustedZone_node1688102900198,
frame2=DropDuplicates_node1688842698270,
keys1=["timeStamp", "user"],
keys2=["sensorReadingTime", "customer_email"],
transformation_ctx="JoinStepTrainer_node1688103008151",
)
# Script generated for node Drop Fields
DropFields_node1688103100583 = DropFields.apply(
frame=JoinStepTrainer_node1688103008151,
paths=[
"customer_serialNumber",
"customer_birthDay",
"customer_customerName",
"customer_email",
"customer_phone",
"customer_shareWithPublicAsOfDate",
"customer_shareWithFriendsAsOfDate",
"customer_lastUpdateDate",
"user",
],
transformation_ctx="DropFields_node1688103100583",
)
# Script generated for node Drop Duplicates
DropDuplicates_node1688843613159 = DynamicFrame.fromDF(
DropFields_node1688103100583.toDF().dropDuplicates(),
glueContext,
"DropDuplicates_node1688843613159",
)
# Script generated for node Machine Learning Zone
MachineLearningZone_node3 = glueContext.getSink(
path="s3://neidhpa-lakehouse-project/machine_learning_curated/",
connection_type="s3",
updateBehavior="LOG",
partitionKeys=[],
enableUpdateCatalog=True,
transformation_ctx="MachineLearningZone_node3",
)
MachineLearningZone_node3.setCatalogInfo(
catalogDatabase="project", catalogTableName="machine_learning_curated"
)
MachineLearningZone_node3.setFormat("json")
MachineLearningZone_node3.writeFrame(DropDuplicates_node1688843613159)
job.commit()