gpt4 book ai didi

apache-spark - Spark : What is the difference between Aggregator and UDAF?

转载 作者:行者123 更新时间:2023-12-04 01:39:09 25 4
gpt4 key购买 nike

在 Spark 的文档中,聚合器:

abstract class Aggregator[-IN, BUF, OUT] extends Serializable

A base class for user-defined aggregations, which can beused in Dataset operations to take all of the elements of a group andreduce them to a single value.


UserDefinedAggregateFunction 是:

abstract class UserDefinedAggregateFunction extends Serializable

The base class for implementing user-defined aggregate functions(UDAF).


根据 Dataset Aggregator - Databricks ,“Aggregator 类似于 UDAF,但接口(interface)是用 JVM 对象而不是 Row 来表示的。”
这两个类看起来很相似,除了接口(interface)中的类型之外,还有什么区别?
一个类似的问题是: Performance of UDAF versus Aggregator in Spark

最佳答案

除了类型之外,一个根本的区别是外部接口(interface):

  • Aggregator需要一个完整的Row (它适用于“强”类型的 API)。
  • UserDefinedAggregationFunction需要一组 Columns .

  • 这使得 Aggregator不太灵活,尽管整体 API 更加用户友好。

    处理状态也有区别:
  • Aggregator是有状态的。取决于其缓冲区字段的可变内部状态。
  • UserDefinedAggregateFunction是无国籍的。缓冲区的状态是外部的。
  • 关于apache-spark - Spark : What is the difference between Aggregator and UDAF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48180598/

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