如何将数据框中的数据写入单个.parquet文件(单个文件中的数据和元数据)到Amazone S3?

时间:2019-03-01 10:36:16

标签: apache-spark amazon-s3

我正在尝试根据一些S3密钥(按名称分区)将DF写入单个实木复合地板文件中。我的要求是每次运行都将数据附加到相同的镶木地板文件中。

这是我使用的代码,但是此代码在每次创建新的镶木地板文件时都会在该文件夹中为每个名称创建文件夹。但是,我的要求是写入单个文件。

df.coalesce(1).write.partitionBy("name").format("parquet").mode(SaveMode.Append).option("fileType", "parquet").save("s3n://ialert-data/store-streaming-data/")

1 个答案:

答案 0 :(得分:0)

您需要使用分区而不是分区,并在重新分区后合并。

df.repartition(df("name")).coalesce(1).write.mode(SaveMode.Append).parquet("s3n://ialert-data/store-streaming-data/")