【发布时间】:2018-11-02 23:29:27
【问题描述】:
我正在使用 DynamicFrame 的 map 方法(或等效的 Map.apply 方法)。我注意到,我传递给这些函数的函数中的任何错误都会被静默忽略,并导致返回的 DynamicFrame 为空。
假设我有一个这样的工作脚本:
import sys
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.transforms import *
glueContext = GlueContext(SparkContext.getOrCreate())
dyF = glueContext.create_dynamic_frame.from_catalog(database="radixdemo", table_name="census_csv")
def my_mapper(rec):
import logging
logging.error("[RADIX] An error-log from in the mapper!")
print "[RADIX] from in the mapper!"
raise Exception("[RADIX] A bug!")
dyF = dyF.map(my_mapper, 'my_mapper')
print "Count: ", dyF.count()
dyF.printSchema()
dyF.toDF().show()
如果我在我的 Glue Dev Endpoint 中使用 gluepython 运行此脚本,我会得到如下输出:
[glue@ip-172-31-83-196 ~]$ gluepython gluejob.py
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/share/aws/glue/etl/jars/glue-assembly.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/lib/spark/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
18/05/23 20:56:46 WARN Client: Neither spark.yarn.jars nor spark.yarn.archive is set, falling back to uploading libraries under SPARK_HOME.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Count: 0
root
++
||
++
++
关于此输出的说明:
- 我看不到
print语句或logging.error语句的结果。 - 没有迹象表明
my_mapper引发了异常。 -
printSchema调用显示生成的 DynamicFrame 上没有架构元数据 -
show方法也没有产生任何输出,表明所有行都消失了。
同样,当我将此脚本保存为 AWS Glue 控制台中的作业并运行它时,该作业未指示发生任何错误 - 作业状态为“成功”。值得注意的是,我确实将print 语句和logging.error 调用输出到作业日志,但仅在常规“日志”中,而不是在“错误日志”中。
我想要的是能够表明我的工作失败了,并且能够轻松找到这些错误日志。最重要的是仅仅表明它失败了。
有没有办法在映射函数中记录错误,以便 Glue 将其作为“错误日志”拾取(并将其放在单独的 AWS CloudWatch Logs 路径中)?如果发生这种情况,它会自动将整个 Job 标记为 Failing 吗?还是有其他方法可以从映射函数中显式失败?
(如果有办法记录错误和/或将作业标记为失败,我的计划是创建一个装饰器或其他实用程序函数,它们将自动捕获映射函数中的异常并确保它们被记录和标记失败)。
【问题讨论】:
-
我不确定如何将 Glue 与 pyspark 一起使用 - 我总是只使用 scala,但您确定您使用的是正确的映射方式吗? Glue Documentation 描述了使用
Map类进行转换。 -
@botchniaque 我已经确认它们是相同的。
Map只是委托给DynamicFrame.map。我提到它们在我的问题中是等价的。
标签: apache-spark pyspark aws-glue