由于 ExecutorLostFailure,无法使用 spark 读取镶木地板文件
Posted
技术标签:
【中文标题】由于 ExecutorLostFailure,无法使用 spark 读取镶木地板文件【英文标题】:Unable to read parquet file using spark due to ExecutorLostFailure 【发布时间】:2020-06-16 14:35:39 【问题描述】:我想使用 Spark 读取 parquet 文件,但它会生成 Py4J 错误:无法创建执行程序。
这就是我生成镶木地板文件的方式:
import pandas as pd
df = pd.DataFrame(data='col1': [1, 2], 'col2': [3, 4])
df.to_parquet('df.parquet')
我是这样读的:
def create_spark(): # create spark session
sc_conf = pyspark.SparkConf()
sc_conf.setAppName("Iteration_3")
# sc_conf.setMaster('spark://some_address:7077')
sc_conf.setMaster('spark://A.B.C.D:7077')
sc_conf.set('spark.executor.memory', '2g')
sc_conf.set('spark.executor.cores', '2')
sc_conf.set('spark.cores.max', '6')
sc_conf.set('spark.logConf', True)
sc_conf.set('spark.driver.host','A.B.C.D')
sc_conf.set('spark.driver.port','42000')
sc_conf.set('spark.blockManager.port','42100')
sc_conf.set('spark.driver.bindAddress','0.0.0.0')
print (sc_conf.getAll())
spark_session = SparkSession.builder.config(conf=sc_conf).getOrCreate()
return spark_session
spark = create_spark()
parquet_file = spark.read.parquet('df.parquet')
这是我得到的错误:
Py4JJavaError Traceback (most recent call last)
<ipython-input-16-ba4073bfd9e9> in <module>
----> 1 parquet_file = spark.read.parquet('df.parquet')
/opt/app-root/lib/python3.6/site-packages/pyspark/sql/readwriter.py in parquet(self, *paths)
314 [('name', 'string'), ('year', 'int'), ('month', 'int'), ('day', 'int')]
315 """
--> 316 return self._df(self._jreader.parquet(_to_seq(self._spark._sc, paths)))
317
318 @ignore_unicode_prefix
/opt/app-root/lib/python3.6/site-packages/py4j/java_gateway.py in __call__(self, *args)
1255 answer = self.gateway_client.send_command(command)
1256 return_value = get_return_value(
-> 1257 answer, self.gateway_client, self.target_id, self.name)
1258
1259 for temp_arg in temp_args:
/opt/app-root/lib/python3.6/site-packages/pyspark/sql/utils.py in deco(*a, **kw)
61 def deco(*a, **kw):
62 try:
---> 63 return f(*a, **kw)
64 except py4j.protocol.Py4JJavaError as e:
65 s = e.java_exception.toString()
/opt/app-root/lib/python3.6/site-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
326 raise Py4JJavaError(
327 "An error occurred while calling 012.\n".
--> 328 format(target_id, ".", name), value)
329 else:
330 raise Py4JError(
Py4JJavaError: An error occurred while calling o90.parquet.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 4 times, most recent failure: Lost task 0.3 in stage 0.0 (TID 3, 172.44.16.104, executor 68): ExecutorLostFailure (executor 68 exited caused by one of the running tasks) Reason: Unable to create executor due to Exception thrown in awaitResult:
Driver stacktrace:
at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1889)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1877)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1876)
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:1876)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:926)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:926)
at scala.Option.foreach(Option.scala:257)
at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:926)
at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:2110)
at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:2059)
at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:2048)
at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:49)
at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:737)
at org.apache.spark.SparkContext.runJob(SparkContext.scala:2061)
at org.apache.spark.SparkContext.runJob(SparkContext.scala:2082)
at org.apache.spark.SparkContext.runJob(SparkContext.scala:2101)
at org.apache.spark.SparkContext.runJob(SparkContext.scala:2126)
at org.apache.spark.rdd.RDD$$anonfun$collect$1.apply(RDD.scala:945)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:112)
at org.apache.spark.rdd.RDD.withScope(RDD.scala:363)
at org.apache.spark.rdd.RDD.collect(RDD.scala:944)
at org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat$.mergeSchemasInParallel(ParquetFileFormat.scala:633)
at org.apache.spark.sql.execution.datasources.parquet.ParquetFileFormat.inferSchema(ParquetFileFormat.scala:241)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$6.apply(DataSource.scala:180)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$6.apply(DataSource.scala:180)
at scala.Option.orElse(Option.scala:289)
at org.apache.spark.sql.execution.datasources.DataSource.getOrInferFileFormatSchema(DataSource.scala:179)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:373)
at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)
at org.apache.spark.sql.DataFrameReader.parquet(DataFrameReader.scala:641)
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:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)
我试图去实现post 中提到的一些事情,但我不认为那里提到的问题,比如 OOM,是我的代码的问题。
【问题讨论】:
您是在本地模型还是在远程集群中运行 spark?这是 sc_conf.setMaster('spark://A.B.C.D:7077') 和实际运行的火花集群吗?如果您在本地运行它,无论哪种方式用于测试目的,我都会建议类似 sc_conf.setMaster('local[*]') 是集群。我不认为我可以在本地做,可以吗? 【参考方案1】:版本不匹配。 Spark 为 2.3.0,PySpark 为 2.4.3。
在我的笔记本中,我运行了!pip install pyspark==2.3.0
,然后推断出架构并且不再出现错误。
【讨论】:
以上是关于由于 ExecutorLostFailure,无法使用 spark 读取镶木地板文件的主要内容,如果未能解决你的问题,请参考以下文章
火花作业中的 Azure databricks 群集错误:ExecutorLostFailure
有没有办法重写 Spark RDD distinct 以使用 mapPartitions 而不是 distinct?