-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytical_dataset_job.py
52 lines (47 loc) · 1.78 KB
/
analytical_dataset_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
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 AWS Glue Data Catalog
AWSGlueDataCatalog_node1705846175992 = glueContext.create_dynamic_frame.from_catalog(
database="db_youtube_cleaned2",
table_name="raw_statistics",
transformation_ctx="AWSGlueDataCatalog_node1705846175992",
)
# Script generated for node AWS Glue Data Catalog
AWSGlueDataCatalog_node1705846175149 = glueContext.create_dynamic_frame.from_catalog(
database="db_youtube_cleaned2",
table_name="cleaned_statistics_reference_data2",
transformation_ctx="AWSGlueDataCatalog_node1705846175149",
)
# Script generated for node Join
Join_node1705846196426 = Join.apply(
frame1=AWSGlueDataCatalog_node1705846175992,
frame2=AWSGlueDataCatalog_node1705846175149,
keys1=["category_id"],
keys2=["id"],
transformation_ctx="Join_node1705846196426",
)
# Script generated for node Amazon S3
AmazonS3_node1705846409578 = glueContext.getSink(
path="s3://youtube-analytics-version",
connection_type="s3",
updateBehavior="UPDATE_IN_DATABASE",
partitionKeys=["region", "category_id"],
enableUpdateCatalog=True,
transformation_ctx="AmazonS3_node1705846409578",
)
AmazonS3_node1705846409578.setCatalogInfo(
catalogDatabase="db_youtube_analytics", catalogTableName="final_analytics"
)
AmazonS3_node1705846409578.setFormat("glueparquet", compression="snappy")
AmazonS3_node1705846409578.writeFrame(Join_node1705846196426)
job.commit()