feat: support `grouping` aggregate function
Which issue does this PR close?
Closes #.
Rationale for this change
Currently datafusion does not implement grouping function.
https://github.com/apache/datafusion/blob/4edbdd7d09d97f361748c086afbd7b3dda972f76/datafusion/physical-expr/src/aggregate/grouping.rs#L80-L84
What changes are included in this PR?
Complete the grouping function.
https://www.postgresql.org/docs/9.5/functions-aggregate.html https://learn.microsoft.com/en-us/sql/t-sql/functions/grouping-transact-sql?view=sql-server-ver15
Are these changes tested?
Yes
Are there any user-facing changes?
Yes. Perhaps we need to include in the documentation instructions for the grouping function.
https://arrow.apache.org/datafusion/user-guide/sql/aggregate_functions.html
Related work: https://github.com/apache/datafusion/issues/2477 https://github.com/apache/datafusion/pull/2486
Thanks @JasonLi-cn for this 👍
I noticed this from PG's document:
. The arguments to the GROUPING operation are not actually evaluated, but they must match exactly expressions given in the GROUP BY clause of the associated query level.
Do we need to do some verifications to make sure the param of
GROUPINGmatchesGROUP BY? Also I see the implementation ofGroupingGroupsAccumulatorassumes the input expr is column, butGROUP BYdoesn't have such a constrain.
Thanks @waynexia for your suggestion. I agree with you and I will make improvements according to your suggestions.
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.