Skip to main content
Cube.create_date_hierarchy(
    name: str,
    *,
    column: Column,
    levels: Mapping[str, str] = frozendict({'Year': 'y', 'Month': 'M', 'Day': 'd'}),
) → None
Create a multilevel date hierarchy based on a date column. The new levels are created by matching a date pattern. Here is a non-exhaustive list of patterns that can be used:

Parameters

name

The name of the hierarchy to create.

column

The column to create the hierarchy from. Its data_type must be LocalDate, LocalDateTime, or ZonedDateTime, and it must belong to an in-memory table, not an external one.

levels

The mapping from the names of the levels to the patterns from which they will be created.
The full date can also be added back as the last level of the hierarchy:
Data inserted into the table after the hierarchy creation will be automatically hierarchized: