关注 spark技术分享,
撸spark源码 玩spark最佳实践

ScalaUDAF

ScalaUDAF — Catalyst Expression Adapter for UserDefinedAggregateFunction

ScalaUDAF is a Catalyst expression adapter to manage the lifecycle of UserDefinedAggregateFunction and hook it in Spark SQL’s Catalyst execution path.

ScalaUDAF is created when:

ScalaUDAF is a ImperativeAggregate.

Table 1. ScalaUDAF’s ImperativeAggregate Methods
Method Name Behaviour

initialize

Requests UserDefinedAggregateFunction to initialize

merge

Requests UserDefinedAggregateFunction to merge

update

Requests UserDefinedAggregateFunction to update

When evaluated, ScalaUDAF…​FIXME

ScalaUDAF has no representation in SQL.

Table 2. ScalaUDAF’s Properties
Name Description

aggBufferAttributes

AttributeReferences of aggBufferSchema

aggBufferSchema

bufferSchema of UserDefinedAggregateFunction

dataType

DataType of UserDefinedAggregateFunction

deterministic

deterministic of UserDefinedAggregateFunction

inputAggBufferAttributes

Copy of aggBufferAttributes

inputTypes

Data types from inputSchema of UserDefinedAggregateFunction

nullable

Always enabled (i.e. true)

Table 3. ScalaUDAF’s Internal Registries and Counters
Name Description

inputAggregateBuffer

Used when…​FIXME

inputProjection

Used when…​FIXME

inputToScalaConverters

Used when…​FIXME

mutableAggregateBuffer

Used when…​FIXME

Creating ScalaUDAF Instance

ScalaUDAF takes the following when created:

ScalaUDAF initializes the internal registries and counters.

initialize Method

initialize sets the input buffer internal binary row as underlyingBuffer of MutableAggregationBufferImpl and requests the UserDefinedAggregateFunction to initialize (with the MutableAggregationBufferImpl).

spark sql ScalaUDAF initialize.png
Figure 1. ScalaUDAF initializes UserDefinedAggregateFunction
Note
initialize is part of ImperativeAggregate Contract.

update Method

update sets the input buffer internal binary row as underlyingBuffer of MutableAggregationBufferImpl and requests the UserDefinedAggregateFunction to update.

Note
update uses inputProjection on the input input and converts it using inputToScalaConverters.
spark sql ScalaUDAF update.png
Figure 2. ScalaUDAF updates UserDefinedAggregateFunction
Note
update is part of ImperativeAggregate Contract.

merge Method

merge first sets:

spark sql ScalaUDAF merge.png
Figure 3. ScalaUDAF requests UserDefinedAggregateFunction to merge
Note
merge is part of ImperativeAggregate Contract.
赞(0) 打赏
未经允许不得转载:spark技术分享 » ScalaUDAF
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏