AWS Glue show方法引发错误

时间:2018-04-09 04:54:02

标签: amazon-web-services pyspark etl aws-glue

我使用AWS Glue使用dev-endpoint执行ETL作业。我试图运行以下代码但执行时出错。几天前我运行它时运行成功。但是,这会增加新运行的错误。

df1=
sqlContext.createDataFrame([("11/25/1991","11/24/1991","11/30/1991")
                        ("11/25/1391","11/24/1992","11/30/1992")], 
schema=['first', 'second', 'third'])
func =  udf (lambda x: datetime.strptime(x, '%m/%d/%Y'), DateType())

df = df1.withColumn('test', func(col('first')))
df.printSchema()
df.show()

这是错误

  Traceback (most recent call last):
  File "/tmp/zeppelin_pyspark-2266243445000109294.py", line 367, in <module>
    raise Exception(traceback.format_exc())
Exception: Traceback (most recent call last):
  File "/tmp/zeppelin_pyspark-2266243445000109294.py", line 360, in <module>
    exec(code, _zcUserQueryNameSpace)
  File "<stdin>", line 27, in <module>
  File "/usr/lib/spark/python/pyspark/sql/dataframe.py", line 318, in show
    print(self._jdf.showString(n, 20))
  File "/usr/lib/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "/usr/lib/spark/python/pyspark/sql/utils.py", line 63, in deco
    return f(*a, **kw)
  File "/usr/lib/spark/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py", line 319, in get_return_value
    format(target_id, ".", name), value)
Py4JJavaError: An error occurred while calling o208.showString.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 15.0 failed 4 times, most recent failure: Lost task 0.3 in stage 15.0 (TID 36, ip-172-31-58-71.us-east-2.compute.internal, executor 5): ExecutorLostFailure (executor 5 exited caused by one of the running tasks) Reason: Container killed by YARN for exceeding memory limits. 7.1 GB of 5.5 GB physical memory used. Consider boosting spark.yarn.executor.memoryOverhead.
Driver stacktrace:
    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1517)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1505)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1504)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
    at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1504)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:814)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:814)
    at scala.Option.foreach(Option.scala:257)
    at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:814)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1732)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1687)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1676)
    at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
    at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:630)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:2029)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:2050)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:2069)
    at org.apache.spark.sql.execution.SparkPlan.executeTake(SparkPlan.scala:336)
    at org.apache.spark.sql.execution.CollectLimitExec.executeCollect(limit.scala:38)
    at org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$collectFromPlan(Dataset.scala:2861)
    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2150)
    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2150)
    at org.apache.spark.sql.Dataset$$anonfun$55.apply(Dataset.scala:2842)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:65)
    at org.apache.spark.sql.Dataset.withAction(Dataset.scala:2841)
    at org.apache.spark.sql.Dataset.head(Dataset.scala:2150)
    at org.apache.spark.sql.Dataset.take(Dataset.scala:2363)
    at org.apache.spark.sql.Dataset.showString(Dataset.scala:241)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:280)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:748)

您认为AWS Glue本身可能存在一些问题。该代码适用于printSchema()方法,而show()方法显示错误。

1 个答案:

答案 0 :(得分:1)

我没有看到上述代码有任何错误,只是我必须使用datetime.datetime.strptime()。

%pyspark
import datetime
from datetime import datetime
import dateutil
from pyspark.sql.functions import udf, col
from pyspark.sql.types import DateType

df1 = sqlContext.createDataFrame([("11/25/1991","11/24/1991","11/30/1991"),("11/25/1391","11/24/1992","11/30/1992")], schema=['first', 'second', 'third'])
func =  udf (lambda x: datetime.strptime(x, '%m/%d/%Y'), DateType())
df1.show()

df = df1.withColumn('test', func(col('first')))
df.printSchema()
df.show()

结果输出:

+----------+----------+----------+
|     first|    second|     third|
+----------+----------+----------+
|11/25/1991|11/24/1991|11/30/1991|
|11/25/1391|11/24/1992|11/30/1992|
+----------+----------+----------+
root
 |-- first: string (nullable = true)
 |-- second: string (nullable = true)
 |-- third: string (nullable = true)
 |-- test: date (nullable = true)
+----------+----------+----------+----------+
|     first|    second|     third|      test|
+----------+----------+----------+----------+
|11/25/1991|11/24/1991|11/30/1991|1991-11-25|
|11/25/1391|11/24/1992|11/30/1992|1391-11-17|
+----------+----------+----------+----------+

这个,我在本地模式下在zeppelin上运行而没有连接到胶水,因为我没有在你提供的上述代码中看到任何胶水上下文对象,所以希望它有效。

我在错误日志中注意到的另一件事是,它报告了一些内存问题,也许你也可以看看它,也许你可以尝试在需要的时候增加DPU。

  

org.apache.spark.SparkException:作业因阶段失败而中止:   阶段15.0中的任务0失败4次,最近失败:丢失任务   阶段15.0中的0.3(TID 36,ip-172-31-58-71.us-east-2.compute.internal,executor 5):ExecutorLostFailure(执行者5退出由其中一个引起   正在运行的任务)原因:容器被YARN杀死超过   记忆限制。使用7.1 GB的5.5 GB物理内存。考虑   提升spark.yarn.executor.memoryOverhead

新列TEST中的结果输出未正确转换,但您认为可以解决它。

由于