aws在写入时的粘合性能

31moq8wy  于 2021-07-09  发布在  Spark
关注(0)|答案(2)|浏览(382)

在执行连接和聚合之后,我希望输出在1个文件中,并基于某个列进行分区。当我使用重分区(1)时,作业占用的时间是1小时,如果我删除准备(1)则该文件将有多个分区,需要30分钟(请参阅下面的示例)。有没有办法把数据写入一个文件??

  1. ...
  2. ...
  3. df= df.repartition(1)
  4. glueContext.write_dynamic_frame.from_options(
  5. frame = df,
  6. connection_type = "s3",
  7. connection_options = {
  8. "path": "s3://s3path"
  9. "partitionKeys": ["choice"]
  10. },
  11. format = "csv",
  12. transformation_ctx = "datasink2")

有没有其他方法可以提高写性能。改变格式有帮助吗?以及如何通过一个文件输出来实现并行性
s3存储示例

  1. **if repartition(1)**// what I want but takes more time
  2. choice=0/part-00-001
  3. ..
  4. ..
  5. choice=500/part-00-001
  6. **if removed**// takes less time but multiple files are present
  7. choice=0/part-00-001
  8. ....
  9. choice=0/part-00-0032
  10. ..
  11. ..
  12. choice=500/part-00-001
  13. ....
  14. choice=500/part-00-0032
polkgigr

polkgigr1#

如果目标是只有一个文件,则使用合并而不是重新分区,这样可以避免数据混乱。

8tntrjer

8tntrjer2#

而不是使用df.repartition(1)
使用df.repartition(“choice”)

  1. df= df.repartition("choice")
  2. glueContext.write_dynamic_frame.from_options(
  3. frame = df,
  4. connection_type = "s3",
  5. connection_options = {
  6. "path": "s3://s3path"
  7. "partitionKeys": ["choice"]
  8. },
  9. format = "csv",
  10. transformation_ctx = "datasink2")

相关问题