-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw_data_job.py
62 lines (53 loc) · 2.67 KB
/
raw_data_job.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
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
args = getResolvedOptions(sys.argv, ["JOB_NAME"])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args["JOB_NAME"], args)
#selecting regions
selected_regions = "region in ('ca','gb','us')"
# Script generated for node datasource0
datasource0_node1705841782488 = glueContext.create_dynamic_frame.from_catalog(
database="youtube_raw",
table_name="raw_statistics",
transformation_ctx="datasource0_node1705841782488",
push_down_predicate = selected_regions
)
print('datasource count',datasource0_node1705841782488.count())
# Script generated for node Change Schema
ChangeSchema_node1705841896753 = ApplyMapping.apply(
frame=datasource0_node1705841782488,
mappings=[
("video_id", "string", "video_id", "string"),
("trending_date", "string", "trending_date", "string"),
("title", "string", "title", "string"),
("channel_title", "string", "channel_title", "string"),
("category_id", "long", "category_id", "long"),
("publish_time", "string", "publish_time", "string"),
("tags", "string", "tags", "string"),
("views", "long", "views", "long"),
("likes", "long", "likes", "long"),
("dislikes", "long", "dislikes", "long"),
("comment_count", "long", "comment_count", "long"),
("thumbnail_link", "string", "thumbnail_link", "string"),
("comments_disabled", "boolean", "comments_disabled", "boolean"),
("ratings_disabled", "boolean", "ratings_disabled", "boolean"),
("video_error_or_removed", "boolean", "video_error_or_removed", "boolean"),
("description", "string", "description", "string"),
("region", "string", "region", "string"),
],
transformation_ctx="ChangeSchema_node1705841896753",
)
resolvechoice2 = ResolveChoice.apply(frame = ChangeSchema_node1705841896753, choice = "make_struct", transformation_ctx = "resolvechoice2")
dropnullfields3 = DropNullFields.apply(frame = resolvechoice2, transformation_ctx = "dropnullfields3")
datasink1 = dropnullfields3.toDF().coalesce(1)
df_final_output = DynamicFrame.fromDF(datasink1, glueContext, "df_final_output")
datasink4 = glueContext.write_dynamic_frame.from_options(frame = df_final_output, connection_type = "s3", connection_options = {"path": "s3://youtube-cleansed-useast1/youtube/raw_statistics/", "partitionKeys": ["region"]}, format = "parquet", transformation_ctx = "datasink4")
job.commit()