如何使用spark将S3中的parquet文件合并为一个parquet文件



我有12个拼花文件,每个文件表示每月的New York Taxi上下车信息,由+500K行组成。我想把这12个文件按行合并成1个文件保存在S3中做机器学习模型。我如何使用pyspark做到这一点我将这12个文件上传到AWS S3文件名称

你可以这样做,如果所有文件都在同一个目录:

val ds = spark.read.parquet("/path/*").coalesce(1)
ds.write.parquet("/path/single")

val ds1 = spark.read.parquet("/path1/file")
val ds2 = spark.read.parquet("/path2/anotherlocation/file")
val ds = ds1.union(ds2)
ds.coalesce(1).write.parquet("/path/single")

这是一个使用Scala的例子,你可以在Java/Python中做同样的事情。

最新更新