我们应该在 dataframe 上使用 groupBy 还是 reduceBy
should we use groupBy on dataframe or reduceBy
虽然 groupBy
apache 中的数据框 spark 稍后使用数据框中的另一列进行聚合。有任何性能问题吗? reduceBy
是更好的选择吗?
df.groupBy("primaryKey").agg(max("another column"))
在 groupBy 中,reduce 作业将按顺序执行,但在 reduceByKey 中,内部会并行触发 运行 多个 reduce 作业,因为它知道 key 和 运行 reduce against key。 ReduceByKey 提供比 groupBy 更好的性能。
您可以对两者进行 运行 聚合。
虽然 groupBy
apache 中的数据框 spark 稍后使用数据框中的另一列进行聚合。有任何性能问题吗? reduceBy
是更好的选择吗?
df.groupBy("primaryKey").agg(max("another column"))
在 groupBy 中,reduce 作业将按顺序执行,但在 reduceByKey 中,内部会并行触发 运行 多个 reduce 作业,因为它知道 key 和 运行 reduce against key。 ReduceByKey 提供比 groupBy 更好的性能。 您可以对两者进行 运行 聚合。