The object of the CubeLoaderFromSource class is used to load data. After initializing the object the following actions are required:
Specify the repository object in the Type property, to which a cube or a time series database is loaded.
Depending on the specified type, specify the object, to which the loading is executed, in the Cube or Rubricator property.
Determine parameters of binding of dimensions to data source fields in the DimensionBindings collection.
Determine parameters of binding of facts to data source fields in the FactBindings collection.
Initialize the data source, from which the loading is executed. The source must support IDtProvider.
After calling the Load method data is loaded.
Consider the example of loading data from the existing repository table. The table has the following fields:
COUNTRY_KEY. Country keys (field type - Integer).
V_DATE. Data, to which value corresponds (field type - Date).
VAL. Value (field type - Real).
Loading is executed to the standard cube with the S_CUBE identifier. The cube structure has two dimensions: a countries dimension with the COUNTRY identifier and a calendar dimension.
Sub LoadData;
Var
MB: IMetabase;
Cube: IStandardCube;
Dims: IStandardCubeDimensions;
Loader: ICubeLoaderFromSource;
Provider: IDtMetabaseProvider;
Bindings: ICubeLoaderDimensionBindings;
Binding: ICubeLoaderDimensionBinding;
FactBinding: ICubeLoaderFactBinding;
Begin
MB := MetabaseClass.Active;
//Source table
Provider := New DtMetabaseProvider.Create;
Provider.Dataset := MB.ItemById("T_DATA").Bind As IDatasetModel;
//Cube, to which data will be loaded
Cube := MB.ItemById("S_Cube").Bind As IStandardCube;
Dims := Cube.Dimensions;
//Cube data loader
Loader := New CubeLoaderFromSource.Create;
Loader.Type := CubeLoaderType.Cube;
Loader.Cube := Cube;
//Set up dimension bindings
Bindings := Loader.DimensionBindings;
//Countries dimension
Binding := Bindings.Add("COUNTRY_KEY");
Binding.AttributeId := "KEY";
Binding.Dimension := Dims.FindById("COUNTRY");
Binding.Dictionary := Binding.Dimension.Dimension;
//Calendar dimension
Binding := Bindings.AddCalendar("V_DATE", DimCalendarLevel.Year);
Binding.Dimension := Dims.Calendar;
//Cube fact
FactBinding := Loader.FactBindings.Add("VAL");
FactBinding.FactKey := 1;
//Load data
Loader.Load(Provider, Null);
End Sub LoadData;
Loading is executed to the time series database with the TSDB identifier. The COUNTRY attribute that refers to the countries dictionary is created in the database structure.
Sub LoadData;
Var
MB: IMetabase;
Rub: IRubricator;
Facts: IMetaDictionary;
Values: IMetaDictionary;
Loader: ICubeLoaderFromSource;
Provider: IDtMetabaseProvider;
Bindings: ICubeLoaderDimensionBindings;
Binding: ICubeLoaderDimensionBinding;
FactBinding: ICubeLoaderFactBinding;
Begin
MB := MetabaseClass.Active;
//Source table
Provider := New DtMetabaseProvider.Create;
Provider.Dataset := MB.ItemById("T_DATA").Bind As IDatasetModel;
//TSDB, to which data will be loaded
Rub := MB.ItemById("TSDB").Bind As IRubricator;
Facts := Rub.Facts;
Values := Rub.Values;
//Initialize data loader
Loader := New CubeLoaderFromSource.Create;
Loader.Type := CubeLoaderType.Rubricator;
Loader.Rubricator := Rub;
//Set up attribute bindings
Bindings := Loader.DimensionBindings;
//Countries dimension
Binding := Bindings.Add("COUNTRY_KEY");
Binding.AttributeId := "KEY";
Binding.MetaAttribute := Facts.Attributes.FindById("COUNTRY");
//Calendar dimension
Binding := Bindings.AddCalendar("V_DATE", DimCalendarLevel.Year);
Binding.MetaAttribute := Values.Attributes.FindByTag(MetaAttributeTag.CalendarDate);
//Bind the Value attribute
FactBinding := Loader.FactBindings.Add("VAL");
FactBinding.MetaAttribute := Values.Attributes.FindByTag(MetaAttributeTag.Value);
//Load data
Loader.Load(Provider, Null);
End Sub LoadData;
See also: