Consider the example of creating a standard cube using the Fore and Fore.NET language. To create a cube, the following objects must be in repository:
A facts dictionary with the FACTS identifier.
A countries dictionary with the COUNTRY identifier.
A calendar dictionary with the CALENDAR identifier.
A table with the STD_DATA identifier having the following fields in its structure:
Value. Value in the specified point (Field type: Real).
Country_Key. Key of the country, for which value is set (Field type: Integer).
V_date. Data, to which value is specified (field type: Date).
The following example creates a new object that is Standard Cube in the repository root and sets up its parameters:
The existing repository dictionary is set as a facts dimension.
One data source is added, the Value field of the source is linked with the first cube fact.
Two dimensions COUNTRY and CALENDAR are added to the cube structure.
The COUNTRY dimension is connected to the Country_Key field by the primary dictionary key; the CALENDAR calendar is connected to the V_date field by the primary index of the Years block.
A relation is created in the cube to set up calculated fact. This relation returns the previous point relative that, in which calculation is executed.
Based on the created relation the formula used for calculation is created for the second cube fact.
After that the cube is saved.
To execute the example, add links to the Cubes, Db, Dimensions, Metabase system assemblies. Write the corresponding Imports strings for the Fore.NET example.
Sub CreateStdCube;
Var
MB: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
StdCube: IStandardCube;
StdDims: IStandardCubeDimensions;
StdDatasets: IStandardCubeDatasets;
FactDim, CountryDim, CalendarDim: IStandardCubeDimension;
StdDataset: IStandardCubeDataset;
FactDimInst: IDimInstance;
KeyAttribute: IDimAttributeInstance;
FactBindings: IStandardCubeFactBindings;
DimBinding: IStandardCubeDimensionBinding;
DimIndex: IDimIndex;
Relation: IStandardCubeRelation;
DataSet_ID: String = "STD_DATA";
Begin
MB := MetabaseClass.Active;
//Information for creating a new repository object
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_STDCUBE;
CrInfo.Id := "New_Std_Cube";
CrInfo.Name := "New standard cube";
CrInfo.Parent := MB.Root;
//Create a cube
MObj := MB.CreateObject(CrInfo).Edit;
StdCube := MObj As IStandardCube;
//Set up cube parameters
StdDims := StdCube.Dimensions;
StdDatasets := StdCube.Datasets;
//Specify existing repository dictionary as a fact dimension
FactDim := StdDims.Add(MB.ItemById("FACTS").Bind As IDimensionModel);
StdCube.ExternalFactDimension := True;
FactDim.FactDimension := True;
//Add a data source
StdDataset := StdDatasets.Add(MB.ItemById(DataSet_ID).Bind As IDatasetModel);
//Link cube fact
FactDimInst := FactDim.OpenDimension;
KeyAttribute := FactDimInst.Attributes.FindById("KEY");
FactBindings := FactDim.FactBindings(StdDataset);
FactBindings.Binding(KeyAttribute.Value(0)).Formula.AsString := DataSet_ID + ".VALUE";
//Add dimensions
CountryDim := StdDims.Add(MB.ItemById("COUNTRY").Bind As IDimensionModel);
CalendarDim := StdDims.Add(MB.ItemById("CALENDAR").Bind As IDimensionModel);
//Link dimensions
//"Countries"
DimIndex := CountryDim.Dimension.Indexes.PrimaryIndex;
DimBinding := CountryDim.Binding(StdDataset);
DimBinding.Index := DimIndex;
DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".COUNTRY_KEY";
//"Calendar"
DimIndex := CalendarDim.Dimension.Blocks.Item("YEARS").Indexes.FindById("INDEX_BLOCK");
DimBinding := CalendarDim.Binding(StdDataset);
DimBinding.Index := DimIndex;
DimBinding.Binding(DimIndex.Attributes.Item(0)).AsString := DataSet_ID + ".V_DATE";
//Create and set up relations
Relation := StdCube.Relations.Add;
Relation.Name := "Shift for point";
Relation.Id := "BEFORE";
Relation.Relation(CalendarDim).AsString := "T.PREV";
//Specify formula for calculated fact
StdCube.CalcBindings.Binding(KeyAttribute.Value(1)).Formula.AsString := "@[" + KeyAttribute.Value(0) + "]-BEFORE[@[" + KeyAttribute.Value(0) + "]]";
MObj.Save;
End Sub CreateStdCube;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Metabase;
Public Sub CreateStdCube(MB: IMetabase);
Var
CrInfo: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
StdCube: IStandardCube;
StdDims: IStandardCubeDimensions;
StdDatasets: IStandardCubeDatasets;
FactDim, CountryDim, CalendarDim: IStandardCubeDimension;
StdDataset: IStandardCubeDataset;
FactDimInst: IDimInstance;
KeyAttribute: IDimAttributeInstance;
FactBindings: IStandardCubeFactBindings;
DimBinding: IStandardCubeDimensionBinding;
DimIndex: IDimIndex;
Relation: IStandardCubeRelation;
DataSet_ID: String = "STD_DATA";
Begin
//Information for creating a new repository object
CrInfo := MB.CreateCreateInfo();
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_STDCUBE As Integer;
CrInfo.Id := "New_Std_Cube";
CrInfo.Name := "New standard cube";
CrInfo.Parent := MB.Root;
//Create a cube
MObj := MB.CreateObject(CrInfo).Edit();
StdCube := MObj As IStandardCube;
//Set up cube parameters
StdDims := StdCube.Dimensions;
StdDatasets := StdCube.Datasets;
//Specify existing repository dictionary as a fact dimension
FactDim := StdDims.Add(MB.ItemById["FACTS"].Bind() As IDimensionModel);
StdCube.ExternalFactDimension := True;
FactDim.FactDimension := True;
//Add a data source
StdDataset := StdDatasets.Add(MB.ItemById[DataSet_ID].Bind() As IDatasetModel);
//Link cube fact
FactDimInst := FactDim.OpenDimension;
KeyAttribute := FactDimInst.Attributes.FindById("KEY");
FactBindings := FactDim.FactBindings[StdDataset];
FactBindings.Binding[KeyAttribute.Value[0]].Formula.AsString := DataSet_ID + ".VALUE";
//Add dimensions
CountryDim := StdDims.Add(MB.ItemById["COUNTRY"].Bind() As IDimensionModel);
CalendarDim := StdDims.Add(MB.ItemById["CALENDAR"].Bind() As IDimensionModel);
//Link dimensions
//"Countries"
DimIndex := CountryDim.Dimension.Indexes.PrimaryIndex;
DimBinding := CountryDim.Binding[StdDataset];
DimBinding.Index := DimIndex;
DimBinding.Binding[DimIndex.Attributes.Item[0]].AsString := DataSet_ID + ".COUNTRY_KEY";
//"Calendar"
DimIndex := CalendarDim.Dimension.Blocks.Item["YEARS"].Indexes.FindById("INDEX_BLOCK");
DimBinding := CalendarDim.Binding[StdDataset];
DimBinding.Index := DimIndex;
DimBinding.Binding[DimIndex.Attributes.Item[0]].AsString := DataSet_ID + ".V_DATE";
//Create and set up relations
Relation := StdCube.Relations.Add();
Relation.Name := "Shift for point";
Relation.Id := "BEFORE";
Relation.Relation[CalendarDim].AsString := "T.PREV";
//Specify formula for calculated fact
StdCube.CalcBindings.Binding[KeyAttribute.Value[1]].Formula.AsString := "@[" + KeyAttribute.Value[0] + "]-BEFORE[@[" + KeyAttribute.Value[0] + "]]";
MObj.Save();
End Sub;
See also: