且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Spark SCALA中的AWS中重命名Spark数据框架输出文件

更新时间:2023-11-22 22:23:46

val tempOutPath = "mediamath.dir"
headerDf.union(outDf)
  .repartition(1)
  .write
  .mode(SaveMode.Overwrite)
  .format("text")
  .option("codec", "gzip")
  .save(tempOutPath)

import org.apache.hadoop.fs._
val sc = spark.sparkContext
val fs = FileSystem.get(sc.hadoopConfiguration)
val file = fs.globStatus(new Path("mediamath.dir/part*.gz"))(0).getPath.getName

fs.rename(new Path("mediamath.dir/" + file), new Path(<aws-s3-path>))

这是我的代码段,请查看是否对您有帮助.

Here is my code snippet please see if this helps you.