d_l*_*_de 1 scala apache-spark apache-spark-sql
我需要根据特定Partition键将数据写入 s3 ,这可以通过使用write.partitionBy. 但是,在这种情况下,我只需要在每个路径中写入一个文件。我正在使用下面的代码来做到这一点。
orderFlow.coalesce(1).write.partitionBy("SellerYearMonthWeekKey")
.mode(SaveMode.Overwrite)
.format("com.databricks.spark.csv")
.option("delimiter", ",")
.option("header", "true")
.save(outputS3Path + "/")
Run Code Online (Sandbox Code Playgroud)
你能帮我找到实现这一目标的最佳方法吗?在上述情况下,我收到 OutOfMemory 错误。
如果您想为每个分区输出一个文件,您可以按中使用的同一列重新分区数据集 partitionBy
orderFlow.repartition("SellerYearMonthWeekKey")
.write.partitionBy("SellerYearMonthWeekKey")
.mode(SaveMode.Overwrite)
.format("com.databricks.spark.csv")
.option("delimiter", ",")
.option("header", "true")
.save(outputS3Path + "/")
Run Code Online (Sandbox Code Playgroud)
这将花费你一次洗牌,但保证每个分区目录有一个文件。