atoti.aggregate_provider module#

class atoti.AggregateProvider#

An aggregate provider pre-aggregates some table columns up to certain levels.

If a step of a query uses a subset of the aggregate provider’s levels and measures, the provider will speed up the query.

An aggregate provider uses additional memory to store the intermediate aggregates. The more levels and measures are added, the more memory it requires.

Example

>>> df = pd.DataFrame(
...     {
...         "Seller": ["Seller_1", "Seller_1", "Seller_2", "Seller_2"],
...         "ProductId": ["aBk3", "ceJ4", "aBk3", "ceJ4"],
...         "Price": [2.5, 49.99, 3.0, 54.99],
...     }
... )
>>> table = session.read_pandas(df, table_name="Seller")
>>> cube = session.create_cube(table)
>>> l, m = cube.levels, cube.measures
>>> cube.aggregate_providers.update(
...     {
...         "Seller provider": tt.AggregateProvider(
...             key="bitmap",
...             levels=[l["Seller"], l["ProductId"]],
...             measures=[m["Price.SUM"]],
...             filter=l["ProductId"] == "cdJ4",
...             partitioning="hash4(Seller)",
...         )
...     }
... )
__init__(*, key='leaf', levels=(), measures=(), filter=None, partitioning=None)#

Initialize an aggregate provider.

Parameters:
  • key (Literal['bitmap', 'leaf']) –

    The key of the provider.

    The bitmap is generally faster but also takes more memory.

  • levels (Iterable[HasIdentifier[LevelIdentifier] | LevelIdentifier]) – The levels to build the provider on.

  • measures (Iterable[HasIdentifier[MeasureIdentifier] | MeasureIdentifier]) – The measures to build in the provider on.

  • filter (Condition[LevelIdentifier, Literal['eq', 'isin'], ~atoti_core.constant.Constant, ~typing.Literal['and'] | None] | None) –

    Only compute and provide aggregates matching this condition.

    The passed condition must be an equality test on a level (handled by the provider or not) or a combination of that kind of condition.

  • partitioning (str | None) –

    The partitioning of the provider.

    Default to the partitioning of the cube’s base table.