Skip to main content
Premium

Extending Aggregate Functions

The built-in functions (count, sum, avg, min, max) and bucket forms (exact, trunc:*, width) cover the dashboard widget use cases shipped with habarico-enterprise. They are declared as str-enum members in habarico_enterprise.aggregations.schema (AggregateFunctionType and GroupByType); each member carries its Django ORM class (Sum, TruncDay, …) and a predicate that checks whether the function applies to a given field type.

Adding a custom function (e.g. percentile, distinct count) is not currently supported: AggregateFunctionType/GroupByType are plain Enum subclasses, and Python raises TypeError: ... cannot be extended for any Enum subclass that already has members. If your service needs a function beyond the built-ins, implement your own endpoint against the model directly rather than extending the /aggregate endpoint.