Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom window frame with AVG aggregate function #4845

Closed
jonmmease opened this issue Jan 7, 2023 · 0 comments · Fixed by #4846
Closed

Support custom window frame with AVG aggregate function #4845

jonmmease opened this issue Jan 7, 2023 · 0 comments · Fixed by #4846
Labels
enhancement New feature or request

Comments

@jonmmease
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant