atoti.Session.create_cube()#

Session.create_cube(base_table, name=None, *, mode='auto', filter=None)#

Create a cube based on the passed table.

Parameters:
  • base_table (Table) – The base table of the cube.

  • name (str | None) – The name of the created cube. Defaults to the name of the base table.

  • mode (Literal['auto', 'manual', 'no_measures']) –

    The cube creation mode:

    • auto: Creates hierarchies for every key column or non-numeric column of the table, and measures for every numeric column.

    • manual: Does not create any hierarchy or measure (except from the count).

    • no_measures: Creates the hierarchies like auto but does not create any measures.

    Example

    >>> table = session.create_table(
    ...     "Table",
    ...     types={"id": tt.STRING, "value": tt.DOUBLE},
    ... )
    >>> cube_auto = session.create_cube(table)
    >>> sorted(cube_auto.measures)
    ['contributors.COUNT', 'update.TIMESTAMP', 'value.MEAN', 'value.SUM']
    >>> list(cube_auto.hierarchies)
    [('Table', 'id')]
    >>> cube_no_measures = session.create_cube(table, mode="no_measures")
    >>> sorted(cube_no_measures.measures)
    ['contributors.COUNT', 'update.TIMESTAMP']
    >>> list(cube_no_measures.hierarchies)
    [('Table', 'id')]
    >>> cube_manual = session.create_cube(table, mode="manual")
    >>> sorted(cube_manual.measures)
    ['contributors.COUNT', 'update.TIMESTAMP']
    >>> list(cube_manual.hierarchies)
    []
    

  • filter (Condition[ColumnIdentifier, Literal['eq', 'ge', 'gt', 'le', 'lt', 'ne', 'isin'], Constant | None, ~typing.Literal['and', 'or'] | None] | None) –

    If not None, only rows of the database matching this condition will be fed to the cube. It can also reduce costs when using DirectQuery since the filter will be applied to the queries executed on the external database to feed the cube.

    Example

    >>> df = pd.DataFrame(
    ...     columns=["Product"],
    ...     data=[
    ...         ("phone"),
    ...         ("watch"),
    ...         ("laptop"),
    ...     ],
    ... )
    >>> table = session.read_pandas(df, table_name="Filtered table")
    >>> cube = session.create_cube(table, "Default")
    >>> cube.query(
    ...     cube.measures["contributors.COUNT"],
    ...     levels=[cube.levels["Product"]],
    ... )
            contributors.COUNT
    Product
    laptop                   1
    phone                    1
    watch                    1
    >>> filtered_cube = session.create_cube(
    ...     table,
    ...     "Filtered",
    ...     filter=table["Product"].isin("watch", "laptop"),
    ... )
    >>> filtered_cube.query(
    ...     filtered_cube.measures["contributors.COUNT"],
    ...     levels=[filtered_cube.levels["Product"]],
    ... )
            contributors.COUNT
    Product
    laptop                   1
    watch                    1
    

Return type:

Cube