Creating a Standard Cube

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:

  1. A facts dictionary with the FACTS identifier.

  2. A countries dictionary with the COUNTRY identifier.

  3. A calendar dictionary with the CALENDAR identifier.

  4. A table with the STD_DATA identifier having the following fields in its structure:

The following example creates a new object that is Standard Cube in the repository root and sets up its parameters:

To execute the example, add links to the Cubes, Db, Dimensions, Metabase system assemblies. Write the corresponding Imports strings for the Fore.NET example.

Fore 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;

Fore.NET Example

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:

Examples