【发布时间】:2019-10-11 07:09:11
【问题描述】:
我想在 DynamicFrame 中获取特定数据。
所以我使用 AWS Glue 控制台并且我有这个 DynamicFrame,在这个 DynamicFrame 中我有一个数据,我需要使用它来指定在 S3 中组织数据的路径。
我想从这个 DynamicFrame 内的日志中获取特定数据
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 = "tb_houpa_logs_glue", table_name = "logs_09_15_15", transformation_ctx = "datasource0"]
## @return: datasource0
## @inputs: []
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "my_table", table_name = "my_log", transformation_ctx = "datasource0")
## @type: ApplyMapping
## @args: [mapping = [("event_type", "string", "event_type", "string"), ("event_timestamp", "timestamp", "event_timestamp", "timestamp"), ("arrival_timestamp", "long", "arrival_timestamp", "long"), ("event_version", "string", "event_version", "string"), ("application", "struct", "application", "struct"), ("client", "struct", "client", "struct"), ("device", "struct", "device", "struct"), ("session", "struct", "session", "struct"), ("attributes", "struct", "attributes", "struct"), ("metrics", "struct", "metrics", "struct"), ("endpoint", "struct", "endpoint", "struct"), ("awsaccountid", "string", "awsaccountid", "string"), ("client_context", "struct", "client_context", "struct"), ("monetization", "struct", "monetization", "struct")], transformation_ctx = "applymapping1"]
## @return: applymapping1
## @inputs: [frame = datasource0]
applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [("event_type", "string", "event_type", "string"), ("event_timestamp", "timestamp", "event_timestamp", "timestamp"), ("arrival_timestamp", "long", "arrival_timestamp", "long"), ("event_version", "string", "event_version", "string"), ("application", "struct", "application", "struct"), ("client", "struct", "client", "struct"), ("device", "struct", "device", "struct"), ("session", "struct", "session", "struct"), ("attributes", "struct", "attributes", "struct"), ("metrics", "struct", "metrics", "struct"), ("endpoint", "struct", "endpoint", "struct"), ("awsaccountid", "string", "awsaccountid", "string"), ("client_context", "struct", "client_context", "struct"), ("monetization", "struct", "monetization", "struct")], transformation_ctx = "applymapping1")
if applymapping1['event_type'] == 'search_active':
event_type = 'search_active'
elif applymapping1['event_type'] == '_session.stop':
event_type = '_session.stop'
else:
event_type = 'testado'
## @type: DataSink
## @args: [connection_type = "s3", connection_options = {"path": "s3://houpa-event-types/teste/" + event_type}, format = "json", transformation_ctx = "datasink2"]
## @return: datasink2
## @inputs: [frame = applymapping1]
datasink2 = glueContext.write_dynamic_frame.from_options(frame = applymapping1, connection_type = "s3", connection_options = {"path": "s3://houpa-event-types/teste/" + event_type}, format = "json", transformation_ctx = "datasink2")
job.commit()
当我执行作业时,返回的是这个错误:
'TypeError: 'DynamicFrame' 对象不可下标'
【问题讨论】:
标签: amazon-web-services pyspark aws-glue