首页 > 解决方案 > 在 s3 存储桶中加载时出现 SparkOutOfMemoryError

问题描述

我有一个数据框并写入 S3 存储桶目标位置。在 Coalesce 用于加载数据和获取 SparkOutOfMemoryError 的代码中。当前的代码 Coalesce 一直在使用多个项目,并且看到很多解决方案建议重新分区,它对我有用。即使它的记录为零,coalesce 也不起作用。有没有其他方法可以在不更改重新分区的情况下解决此问题?

代码:

empsql = 'Select * From Employee'
df = spark.sql(empsql) ##Spark is configured
df.coalesce(2).write.mode('overwrite').format("parquet").option("delimiter",'|').save(s3_path, header = True)

错误:

org.apache.spark.SparkException:写入行时任务失败。在 org.apache.spark.sql.execution.datasources.FileFormatWriter$.org$apache$spark$sql$execution$datasources$FileFormatWriter$$executeTask 在 org.apache.spark.sql.execution.datasources.FileFormatWriter$$anonfun$ write$1.apply at org.apache.spark.sql.execution.datasources.FileFormatWriter$$anonfun$write$1.apply at org.apache.spark.scheduler.ResultTask.runTask at org.apache.spark.scheduler.Task.run at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply at org.apache.spark.util.Utils$.tryWithSafeFinally at org.apache.spark.executor.Executor$TaskRunner.run at java.util. concurrent.ThreadPoolExecutor.runWorker at java.util.concurrent.ThreadPoolExecutor$Worker.run at java.lang.Thread.run 原因:org.apache.spark.memory。

标签: scalaapache-sparkamazon-s3apache-spark-sqlout-of-memory

解决方案


不确定这是否适合您,但请尝试这样做

df.coalesce(2,shuffle=true).write.mode('overwrite').format("parquet").option("delimiter",'|').save(s3_path, header = True)

shuflle =true 将添加一个随机播放步骤。分区将并行执行。该行为类似于使用重新分区


推荐阅读