Adding New Cube Measures
This page provides a description of how we can add a measure. 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 Reference Implementation.
Step 1 - Modify the schema selection
Modify the Cube’s schema so that the Field can be found and set to be a hierarchy. In this case, our modifications will be made in the createBASelection()
method or createSASchemaSelectionDescription()
method for the BA or SA Cube, respectively.
The snippet is from the BA Cube’s Selection config.
note
Make sure that any new field added to the selection does not exist in the selection ready, and that it points to a corresponding field in a datastore.
ISelectionDescriptionBuilder.HasAllFields hasSomeFields = StartBuilding.selection(dsSchemaDesc.asDatabaseSchema())
.fromBaseStore(BAStoreNames.BA_BASE_STORE_NAME)
.withAllFields()
// BA_BASE_TO_TRADE_DESCRIPTION_REF
.usingReference(BAStoreNames.BA_BASE_TO_TRADE_DESCRIPTION_REF)
.withAllFields()
.except(BAStoreNames.TRADE_DESCRIPTION_AS_OF_DATE,
BAStoreNames.TRADE_DESCRIPTION_TRADE_ID,
BAStoreNames.TRADE_DESCRIPTION_REFERENCE_NAME)
...
// Adding the TestField to selection
.usingReference("BaseStore to TestFieldStore") // Reference from the Base Store to our new field's store
.withAllFields()
.except("AsOfDate", "TradeId"); // Exclude fields that are found in other stores. The application will not start if the selection has duplicate fields unintentionally.
Step 2 - Define measure
In this case, we need to extend the BAMeasureBuilder
class for creating measures.
public class ExtendedBAMeasureBuilder implements BAMeasureBuilder {
@Override
public void measures(ICopperContext context) {
return Copper.sum("TestField");
super.measures(context);
}
}
To read more about creating measures with Copper, see Creating and publishing measures.
Step 3 - Application config
Navigate to the configuration class where the original MeasureBuilder class (BAMeasureBuilder
) was used. In this case,
com.activeviam.cvarc.starter.cfg.impl.BACubeConfig.java
, and replace the old MeasureBuilder class with the newly extended one.
cvarc-starter/src/main/java/com/activeviam/cvarc/starter/cfg/impl
@Override
public ICanBuildCubeDescription<IActivePivotInstanceDescription> configureCubeBuilder(
final INamedCubeDescriptionBuilder builder) {
return builder
- .withMeasures(BAMeasureBuilder::measures)
+ .withMeasures(ExtendedBAMeasureBuilder::measures) // Reference the Extended measure builder
...
}