I am new to AWS Glue ETL. I am trying to perform a simple calculation and add the derived column to target table list. When I query, i can see the data, but I am struggling to add it to my final data set. Please help me on the same at the earliest. Thanks
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
## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)
## @type: DataSource
## @args: [database = "stg", table_name = "xyz", transformation_ctx = "datasource0"]
## @return: datasource0
## @inputs: []
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "stg", table_name = "wind_gust", transformation_ctx = "datasource0")
## ==== Transformation ======
datasource0.toDF().createOrReplaceTempView("view_dyf")
sqlDF = spark.sql("select * from view_dyf").show()
## convert units from EU to US units
us_unit_conv =spark.sql("""SELECT IF (mesurement_type = 'm s-1', round(units * 1.151,2),
IF (mesurement_type = 'm', round(units / 1609.344,2),
IF (mesurement_type = 'Pa', round(units /6894.757,2),0) )
)as new_unit
from view_dyf""")
applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [("time", "string", "Time", "string"), ("latitude", "double", "Latitude", "double"), ("longitude", "double", "Longitude", "double"), ("units", "double", "EU_Units", "double"), ("mesurement_type", "string", "EU_Unit_Type", "string"), ("variable_name", "string", "Variable_Name", "string")], transformation_ctx = "applymapping1")
I added new derived column as - ("us_unit_conv", "double", "US_Units", "double") . Please refer below
applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [("time", "string", "Time", "string"), ("latitude", "double", "Latitude", "double"), ("longitude", "double", "Longitude", "double"), ("units", "double", "EU_Units", "double"), ("mesurement_type", "string", "EU_Unit_Type", "string"), ("us_unit_conv", "double", "US_Units", "double"), ("variable_name", "string", "Variable_Name", "string")], transformation_ctx = "applymapping1")