-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtube-analysis-project-raw-csv-to-parquet
72 lines (65 loc) · 2.47 KB
/
youtube-analysis-project-raw-csv-to-parquet
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
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
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 raw_data
raw_data_node1 = glueContext.create_dynamic_frame.from_options(
format_options={
"quoteChar": '"',
"withHeader": True,
"separator": ",",
"optimizePerformance": False,
},
connection_type="s3",
format="csv",
connection_options={
"paths": ["s3://youtube-analysis-project-raw-useast1-dev/raw_statistics/"],
"recurse": True,
},
transformation_ctx="raw_data_node1",
)
# Script generated for node ApplyMapping
ApplyMapping_node2 = ApplyMapping.apply(
frame=raw_data_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", "string", "category_id", "bigint"),
("publish_time", "string", "publish_time", "string"),
("tags", "string", "tags", "string"),
("views", "string", "views", "bigint"),
("likes", "string", "likes", "bigint"),
("dislikes", "string", "dislikes", "bigint"),
("comment_count", "string", "comment_count", "bigint"),
("thumbnail_link", "string", "thumbnail_link", "string"),
("comments_disabled", "string", "comments_disabled", "boolean"),
("ratings_disabled", "string", "ratings_disabled", "boolean"),
("video_error_or_removed", "string", "video_error_or_removed", "boolean"),
("description", "string", "description", "string"),
("region", "string", "region", "string"),
],
transformation_ctx="ApplyMapping_node2",
)
# Script generated for node transformed_data
transformed_data_node3 = glueContext.write_dynamic_frame.from_options(
frame=ApplyMapping_node2,
connection_type="s3",
format="glueparquet",
connection_options={
"path": "s3://youtube-analysis-project-raw-cleansed-role/youtube/raw_statistics/",
"partitionKeys": ["region"],
},
format_options={"compression": "snappy"},
transformation_ctx="transformed_data_node3",
)
job.commit()