Mappings: IValidationCustomMappings;
The Mappings property returns the collection of data source mappings.
Data source mappings are used if mapping expression uses elements from different data sources. Time series databases and standard cubes containing a calendar dimension can be used as data sources.
Executing the example requires that the repository contains time series databases with the TSDB and SDB_VALID identifiers. Both time series databases should contain a series attribute with the CITY identifier. The TSDB database should also contain a validation rule of the Compare by Expression type with the VALID_CUSTOM identifier.
Add links to the Cubes, Dimensions system assemblies. Metabase, Ms, Rds.
Sub UserProc;
Var
mb: IMetabase;
TSDBExt, TSDBVal: IMetabaseObjectDescriptor;
ValidObj: IMetabaseObject;
ValidFilter: IValidationFilter;
Custom: IValidationCustom;
Mappings: IValidationCustomMappings;
Map: IValidationCustomMapping;
Rub: IRubricator;
DimVal, DimEx: IDimInstance;
Transform: IMsFormulaTransform;
Formula: IMsFormula;
Det: IMsDeterministicTransform;
Inputs: IMsFormulaTransformVariables;
TransformVar: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Term: IMsFormulaTerm;
SelectionFilter: IValidationSelectionFilter;
SelVals: IValidationSelectionValues;
ValidExecSett: IValidationExecuteSettings;
ValidExecRun: IValidationExecRun;
Begin
mb := MetabaseClass.Active;
// Get compared time series database (TSDB 1)
TSDBVal := Mb.ItemById("TSDB");
// Get validation rule
ValidObj := Mb.ItemByIdNamespace("VALID_CUSTOM", TSDBVal.Key).Edit;
ValidFilter := ValidObj As IValidationFilter;
ValidFilter.Kind := ValidationDetailsKind.Custom;
// Get rule parameters
Custom := ValidFilter.Details As IValidationCustom;
// Get attribute mapping parameters
Mappings := Custom.Mappings;
// Clear existing mappings
Mappings.Clear;
// Get time series database used for comparison (TSDB 2)
TSDBExt := Mb.ItemById("TSDB_VALID");
// Add a new mapping
map := Mappings.AddStub(TSDBExt.Bind As IVariableStub);
// Get dimension corresponding to the CITY attribute in the TSDB 1
Rub := TSDBVal.Bind As IRubricator;
DimVal := Rub.Facts.Attributes.FindById("CITY").ValuesObject.Open(Null) As IDimInstance;
// Get dimension corresponding to the CITY attribute in TSDB 2
Rub := TSDBExt.Bind As IRubricator;
DimEx := Rub.Facts.Attributes.FindById("CITY").ValuesObject.Open(Null) As IDimInstance;
// Add dimension data binding
map.AddBinding(DimVal, DimEx);
// Set rule calculation mode
Custom.CalculationType := MsCalculationType.Pointwise;
// Get rule calculation parameters
Transform := Custom.Transform;
Formula := Transform.FormulaItem(0);
Formula.Kind := MsFormulaKind.Deterministic;
Det := Formula.Method As IMsDeterministicTransform;
// Get collection of input variables
Inputs := Transform.Inputs;
// Add input variable from TSDB 2
TransformVar := Inputs.Add(map.ExternalStub);
Tree := TransformVar.SlicesTree(TransformVar);
Slice := Tree.CreateSlice(1);
Term := Det.Operands.Add(Slice);
// Add variable to expression
Det.Expression.AsString := Term.TermToInnerText;
// Add input variable from TSDB 1
TransformVar := Transform.Inputs.Add(map.ValidationStub);
Tree := TransformVar.SlicesTree(TransformVar);
Slice := Tree.CreateSlice(1);
Term := Det.Operands.Add(Slice);
// Form final expression with both variables
Det.Expression.AsString := Det.Expression.AsString + ">" + Term.TermToInnerText;
// Get data filtering parameters used for validation
SelectionFilter := Custom.SelectionFilter;
// Clear current filter
SelectionFilter.Clear;
// Add dimension used for filtering
SelVals := SelectionFilter.Add(DimVal.CreateSelection);
// Set selection for filtering by dimension
SelVals.Selection.SelectElement(0, False);
// Save changes of validation rule
ValidObj.Save;
// Execute rule
ValidExecSett := New ValidationExecuteSettings.Create;
ValidExecRun := ValidFilter.Execute(ValidExecSett);
End Sub UserProc;
After executing the example calculation expression is set for validation rule and it is based on series from two different time series databases. The series, which should be validated, are also set for the rule.
See also: