-
Notifications
You must be signed in to change notification settings - Fork 0
/
glue_job_pyspark_code.py
71 lines (61 loc) · 2.59 KB
/
glue_job_pyspark_code.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
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)
predicate_pushdown = "region in ('ca','gb','us')"
# Script generated for node S3 bucket
S3bucket_node1 = glueContext.create_dynamic_frame.from_catalog(
database="de-yt-raw",
table_name="raw_statistics",
transformation_ctx="S3bucket_node1",
push_down_predicate = predicate_pushdown
)
# Script generated for node ApplyMapping
ApplyMapping_node2 = ApplyMapping.apply(
frame=S3bucket_node1,
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", "bigint"),
("publish_time", "string", "publish_time", "string"),
("tags", "string", "tags", "string"),
("views", "long", "views", "bigint"),
("likes", "long", "likes", "bigint"),
("dislikes", "long", "dislikes", "bigint"),
("comment_count", "long", "comment_count", "bigint"),
("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="ApplyMapping_node2",
)
resolvechoice2 = ResolveChoice.apply(frame=ApplyMapping_node2,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")
# Script generated for node S3 bucket
S3bucket_node3 = glueContext.write_dynamic_frame.from_options(
frame=dropnullfields3,
connection_type="s3",
format="glueparquet",
connection_options={
"path": "s3://de-yt-cleansed-useast2-dev/youtube/raw_statistics/",
"partitionKeys": ["region"],
},
transformation_ctx="S3bucket_node3",
)
job.commit()