Load(Source: Object; CreateInfo: IMetabaseObjectCreateInfo): IMetabaseObject;
Source. The data source described by the IDtProvider interface.
CreateInfo. Information about created cube. If information is missing or loading to the current cube is executed, the Null value must be passed as a parameter.
The Load method executes data loading.
A new cube is created before loading. A cube is based on the information passed by the CreateInfo parameter. If parameter is not specified, the information about the cube is generated automatically, and the cube is saved to the folder specified in the Parent property.
A table is created in the repository according to the information about bindings that must be set for dimensions and facts. The data will be further loaded to this table. The cube structure is formed, bindings among dimensions, facts and tables are determined, and the cube is saved after creating the table.
Data is loaded from the source to the table as follows:
The data record is read from the source.
The value of each field is taken in the record alternately and the following operation is executed:
If the field is linked to the cube dimension, the field value is searched among the dimension elements. The search is executed by values of the attribute specified in the AttributeId property. If the element is not found, it is added to appropriate dictionary. The key of the obtained element is recorded to appropriate field of the table created to store cube data.
If the field is linked with the calendar dimension or the fact, the value is recorded to appropriate table field without changes.
Executing the example requires that the repository contains an MDM repository with the MDM identifier and a folder with the F_CUBES identifier, which stores cubes. Also, the C:\Data.xls file is required.
Sub UserProc;
Var
MB: IMetabase;
Loader: ICubeLoaderFromSource;
Provider: IDtExcelProvider;
MDM: IRdsDatabaseInstance;
Bindings: ICubeLoaderDimensionBindings;
Binding: ICubeLoaderDimensionBinding;
i: Integer;
Begin
MB := MetabaseClass.Active;
MDM := MB.ItemById("MDM").Open(Null) As IRdsDatabaseInstance;
//Data source for cube
Provider := New DtExcelProvider.Create;
Provider.DriverVersion := "Excel 8.0";
Provider.File := "C:\Data.xls";
Provider.HasHeader := True;
Provider.Query := "Select * From [Sheet1$]";
//Cube data loader
Loader := New CubeLoaderFromSource.Create;
Loader.CreateCacheKeeper := True;
Loader.RdsDatabase := MDM;
Loader.Database := MDM.DatabaseInstance;
Loader.Parent := MB.ItemById("F_CUBES").Bind;
//Initialize dimensions and facts bindings
Loader.Init(Provider);
//Change dictionary level bound to calendar dimension
Bindings := Loader.DimensionBindings;
For i := 0 To Bindings.Count - 1 Do
Binding := Bindings.Item(i);
If Binding.IsCalendar Then
Binding.CalendarLevel := DimCalendarLevel.Year;
End If;
End For;
//Cube creation and data loading
Loader.Load(Provider, Null);
End Sub UserProc;
On executing the example the import object from Excel and the cube data loader are initialized. The dimensions bindings and facts of created cube are set up according to the information about data source fields. A new standard cube, necessary dictionaries and dimensions, and the table to store data are created on executing the Load method. The data is imported to the created table.
See also: