Я очень новичок в использовании AWS Glue и Spark.Я пытаюсь запустить задание ETL, поэтому мои данные, которые в настоящее время анализируются как три отдельных столбца (год, месяц и день), и мне нужно объединить эти столбцы в формате datetime (или timestamp).Клей сгенерировал базовый скрипт, к которому я пытаюсь добавить эту логику, но у меня небольшой успех.
Вот соответствующая часть кода:
timestampedDf = dropnullfields3.toDF()
timestampedDf = timestampedDf.withColumn("snap_timestamp", datetime.date(year=int(timestampedDf['year']),day=int(timestampedDf['day']),month=int(timestampedDf['month']))
timestamped4 = DynamicFrame.fromDF(timestampedDf, glueContext, "timestamped4")
И регистраторвозвращает мне следующую ошибку:
Синтаксическая ошибка: Файл "/tmp/g-8b0c4794d23f8afeb757fae2a20be7a4b9222fef-5379414877065320437/script_2019-03-20-14-12-14.py", строка 40 timestamped4 = DynamicFrame.ftimestampedDf, glueContext, "timestamped4") SyntaxError: неверный синтаксис
А вот полный код для справки.
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
import datetime
## @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 = "perseus-reporting-db", table_name = "charges_dev_perseus_reporting", transformation_ctx = "datasource0"]
## @return: datasource0
## @inputs: []
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "perseus-reporting-db", table_name = "charges_dev_perseus_reporting", transformation_ctx = "datasource0")
## @type: ApplyMapping
## @args: [mapping = [("amount", "double", "amount", "double"), ("customerid", "string", "customerid", "string"), ("status", "string", "status", "string"), ("createdat", "string", "createdat", "string"), ("year", "string", "year", "string"), ("month", "string", "month", "string"), ("day", "string", "day", "string")], transformation_ctx = "applymapping1"]
## @return: applymapping1
## @inputs: [frame = datasource0]
applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [("amount", "double", "amount", "double"), ("customerid", "string", "customerid", "string"), ("status", "string", "status", "string"), ("createdat", "string", "createdat", "string"), ("year", "string", "year", "string"), ("month", "string", "month", "string"), ("day", "string", "day", "string")], transformation_ctx = "applymapping1")
## @type: ResolveChoice
## @args: [choice = "make_cols", transformation_ctx = "resolvechoice2"]
## @return: resolvechoice2
## @inputs: [frame = applymapping1]
resolvechoice2 = ResolveChoice.apply(frame = applymapping1, choice = "make_cols", transformation_ctx = "resolvechoice2")
## @type: DropNullFields
## @args: [transformation_ctx = "dropnullfields3"]
## @return: dropnullfields3
## @inputs: [frame = resolvechoice2]
dropnullfields3 = DropNullFields.apply(frame = resolvechoice2, transformation_ctx = "dropnullfields3")
timestampedDf = dropnullfields3.toDF()
timestampedDf = timestampedDf.withColumn("snap_timestamp", datetime.date(year=int(timestampedDf['year']),day=int(timestampedDf['day']),month=int(timestampedDf['month']))
timestamped4 = DynamicFrame.fromDF(timestampedDf, glueContext, "timestamped4")
## @type: DataSink
## @args: [catalog_connection = "s3-rds-conn-perseus", connection_options = {"dbtable": "charges_dev_perseus_reporting", "database": "reporting-db"}, transformation_ctx = "datasink4"]
## @return: datasink4
## @inputs: [frame = dropnullfields3]
datasink4 = glueContext.write_dynamic_frame.from_jdbc_conf(frame = timestamped4, catalog_connection = "s3-rds-conn-perseus", connection_options = {"dbtable": "charges_dev_perseus_reporting", "database": "reporting-db"}, transformation_ctx = "datasink4")
job.commit()
Заранее спасибо!