Adding New Cube Measures
This page provides a description of how we can add a measure. It features an example in which we use the ‘CustomProjected’ field from a store which we previously added. For a full walk-through on how this store was added to the cube, see Adding New Data Loading or Unloading Topics.. The techniques employed are generic examples that can be extended, adapted and repeated for any use case that we need. In all cases, we make minimal changes to the Accelerator Reference Implementation.
Step 1 - (Optional) Modify the selection description
If the field we want to turn into a measure is not currently in our 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 extraSchemaSelections_CUBENAME_
.
Cube | Qualifier |
---|---|
Var-ES | extraSchemaSelectionsVar |
Sensi | extraSchemaSelectionsSensi |
PNL | extraSchemaSelectionsPnl |
For example:
@Qualifier("extraSchemaSelectionsVar")
@Bean
UnaryOperator<CanUseOtherReference> extraSchemaSelections() {
return builder -> builder
.usingReference(storesToPath(TRADE_BASE_STORE_NAME, "TESTSTORE"))
.withAllFields()
.except(AS_OF_DATE, RISK_CLASS);
}
Step 2 - Define measure
In this case we will create a new bean to define our new measure with the qualifier @Qualifier("varEsCopperMeasures")
.
Cube | Qualifier |
---|---|
Var-ES | varEsCopperMeasures |
Sensi | sensiCopperMeasures |
PNL | pnlCopperMeasures |
@Configuration
public class ExtendedMeasureBuilder {
@Qualifier("varEsCopperMeasures")
public void measures(ICopperContext context) {
Copper.sum("CustomProjected").publish(context);
}
}
To read more about creating measures with Copper 2, see Creating and publishing measures.
Step 3 - Application config
Navigate to the application config RiskStarterConfig
: risk-starter/src/main/java/com/activeviam/risk/starter/cfg/impl/RiskStarterConfig.java
Add ExtendedMeasureBuilder
to the import classes.
@Configuration
@Import(value = {
...
ExtendedMeasureBuilder.class,
...
})
Suggested Further Reading
Adding a New Cube Hierarchy
Adding a New KPI