> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Adding new cube hierarchies

> Guide to adding new cube hierarchies in Atoti FRTB by exposing datastore fields as cube levels

This page provides a description of how to expose a datastore field as a cube level. It features an example in which a calculated column
`calculated` from a new store is exposed as a level. For a full walk-through on how this store was added to the cube,
see [Adding and Populating a New Store](https://docs.activeviam.com/solutions/frtb/6.0/dev/dev-extensions/etl/creating-and-loading-a-custom-store.md). Plus, to see how the column calculator was implemented,
see [Enriching File Fields by Adding Column Calculators](https://docs.activeviam.com/solutions/frtb/6.0/dev/dev-extensions/etl/enriching-file-field-adding-column-calculators.md).

The techniques employed are generic examples that can be extended, adapted and repeated for any use case required. In all cases, minimal changes are made to
the Reference Implementation.

 

## Step 1 - (Optional) Modify the schema selection description

If the field to turn into a level is not currently in the schema selection, then the first step is to add it.

The cube selection is made by retrieving all fields from a datastore except unwanted ones, so adding an extra field to an existing store will add it to the
selection. Only extra datastore fields will need a change on the selection.

Fields are added to the schema selection by creating a Spring Bean with type `UnaryOperator<CanUseOtherReference>` and qualifier
`SchemaSelection_CUBENAME_` (for example,
`SchemaSelectionStandardisedApproachCube`).

For example:

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
    @Qualifier("SchemaSelectionStandardisedApproachCube")
    @Bean
    UnaryOperator<CanUseOtherReference> extraSchemaSelections() {
        return builder -> builder
            .usingReference(storesToPath(SA_SENSITIVITIES_STORE_NAME, "TESTSTORE"))
            .withAllFields()
            .except(AS_OF_DATE, RISK_CLASS);
    }
```

## Step 2 - Create the level

The field in the schema selection can now be turned into a level in the cube.

Dimensions, hierarchies, and levels can be added to the cube configuration by creating Spring Beans with type `DimensionsAdder`
and qualifier `Dimensions_CUBENAME_` (for example,`DimensionsStandardisedApproachCube`).

For example:

```java theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
@Qualifier("DimensionsStandardisedApproachCube")
@Order(50)
@Bean
public DimensionsAdder dimensions() {
    return builder -> builder
        .withDimension("Sign")
        .withHierarchyOfSameName()
        .withLevel("calculated");
}           
```

> [!NOTE]
>
> The order has been set to 50 so that this dimension is added after the existing dimensions (order=20) and before the epoch dimension
> (order=99).

## Step 3 - Include the modifications in FRTBConfig

These beans can be placed in either of the following locations:

* `com/activeviam/frtb/starter/cfg/impl/CubesDimensionsConfig.java` directly with other dimension beans
* moved to a new configuration class. If you choose this option, be sure to include the configuration classes which contain the beans in the application config class `FRTBConfig` located
  in `/frtb-starter/src/main/java/com/activeviam/frtb/starter/cfg/impl/`

## When using DirectQuery

When using DirectQuery, perform the steps as listed above. There are no additional requirements.

> [!WARNING]
>
> The DirectQuery and in-memory Atoti servers must be configured identically. There must not be any hierarchies in the DirectQuery data node that do not exist in the in-memory one.

## Suggested further reading

[Adding New Cube Measures](https://docs.activeviam.com/solutions/frtb/6.0/dev/dev-extensions/cube/add-a-new-cube-measure.md)

[Adding New Cube KPIs](https://docs.activeviam.com/solutions/frtb/6.0/dev/dev-extensions/cube/add-a-new-kpi.md)
