Aws Glue Etl Transformations
In This Article, We Explain How to Do Etl Transformations in Amazon’s Glue. for Background Material Please Consult How to Join Tables in Aws Glue. You First...
In this article, we explain how to do ETL transformations in Amazon’s Glue. For background material please consult How To Join Tables in AWS Glue. You first need to set up the crawlers in order to create some data.
By this point you should have created a titles DynamicFrame using this code below. Now we can show some ETL transformations.
from pyspark.context import SparkContext from awsglue.context import GlueContext from awsglue.transforms import * glueContext = GlueContext(SparkContext.getOrCreate()) titles = glueContext.create_dynamic_frame.from_catalog(database="moviesandratings", table_name="movieswalker")
Select fields
This ETL transformation creates a new DynamicFrame by taking the fields in the paths list. We use toDF().show() to turn it into Spark Dataframe and print the results.
titles.select_fields(paths=["tconst","primaryTitle"]).toDF().show()
Must Read
Map
The map function iterates over every record (called a DynamicRecord) in the DynamicFrame and runs a function over it.
First create a function that takes a DynamicRecord as an argument and returns the DynamicRecord. Here we take one column and make it uppercase:
def upper(rec): rec["tconst"]=rec["tconst"].upper() return rec
Then call that function on the DynamicFrame titles.
Map.apply(frame=titles,f=upper).toDF().show()