gpt4 book ai didi

apache-spark - Spark pivot groupby 性能很慢

转载 作者:行者123 更新时间:2023-12-04 04:57:21 24 4
gpt4 key购买 nike

我正在尝试旋转原始数据大小为 6 GB 的数据帧,它曾经需要 30 分钟的时间(聚合函数 sum ):

x_pivot = raw_df.groupBy("a", "b", "c", "d", "e","f")
.pivot("g")
.agg(sum(raw_df("h")
.cast(DoubleType))
.alias(""), sum(raw_df("i"))
.alias("i"))

当我首先将聚合函数更改为 时,它开始花费 1.5 小时。
您能否帮助我理解为什么聚合函数会影响性能以及如何提高性能?

最佳答案

为了获得最佳性能,请指定数据透视列的不同值(如果您知道的话)。否则,将立即启 Action 业以确定它们。

像这样,
在 as 列表中

x_pivot = raw_df.groupBy("a", "b", "c", "d", "e","f")
.pivot("g",["V1","V2","V3"])
.agg(sum(raw_df("h")
.cast(DoubleType))
.alias(""), sum(raw_df("i"))
.alias("i"))

V1、V2、V3 是来自“g”列的不同值。

关于apache-spark - Spark pivot groupby 性能很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50295015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com