首页 > 解决方案 > Spark,为什么删除列会导致 Spark 作业失败?

问题描述

在 Spark 2.0 中,我正在运行一个 pyspark 作业,我从表中读取数据,添加一些列,其逻辑基于 30 天的数据窗口,然后我使用df.createOrReplaceTempView后续spark.sql(create table as select * from ...)在 HDFS 中创建表。

该作业成功运行并在 HDFS 中创建了一个表。但是,我不需要我刚刚在数据框中创建的所有列。我只需要一半的新列,因此我添加了一些逻辑来删除我不需要的列(所有这些将被删除的列都是最近创建的)。当我运行 drop `df = df.select([c for c in df.columns if c not in ('a','b','d','e')]) 时,火花作业现在失败了!

错误:Job aborted due to stage failure: Task 139 in stage 1.0 failed 4 times, most recent failure: Lost task 139.3 in stage 1.0 (TID 405, myhost, executor 197): ExecutorLostFailure (executor 197 exited caused by one of the running tasks) Reason: Container marked as failed: container_111 on host: myhost. Exit status: 143. Diagnostics: Container killed on request. Exit code is 143

标签: apache-sparkpysparkapache-spark-sql

解决方案


您可以使用 .drop("colname") 从数据框中删除列。

df1=df.drop("a","b","c","d")

希望它可以帮助你。


推荐阅读