Skip to content

Support custom window frame with AVG aggregate function #4845

@jonmmease

Description

@jonmmease

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
I would like DataFusion to support using the avg aggregate function in a window with custom frame.

Here is a working example using sum:

select sum(column1) OVER(ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) from (values (1.0), (2.0), (3.0)) as sq;
+-----------------+
| SUM(sq.column1) |
+-----------------+
| 1               |
| 3               |
| 5               |
+-----------------+

But it does not work for avg:

select avg(column1) OVER(ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) from (values (1.0), (2.0), (3.0)) as sq;
ArrowError(ExternalError(ArrowError(ExternalError(NotImplemented("Retractable Accumulator hasn't been implemented for Avg { name: \"AVG(sq.column1)\", expr: Column { name: \"column1\", index: 0 }, data_type: Float64 } yet")))))

Describe the solution you'd like
I would like avg to support use in windows with custom frames.

Additional context
Looking at the implementation briefly, I think AvgAccumulator needs an implementation of retract_batch, similar to this implementation for SumAccumulator:

https://github.com/apache/arrow-datafusion/blob/3cc607de4ce6e9e1fd537091e471858c62f58653/datafusion/physical-expr/src/aggregate/sum.rs#L256-L262

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions