AttachArray(Value: Array);
AttachArray(Value: System.Array);
Value. Array from which the data is loaded.
The AttachArray method loads data from an array into a data source.
Dimension of array should correspond to quantity and the size of fields that are created in a data source.
Executing the example requires that the repository contains a time series database with the FC identifier. The attribute referring to MDM dictionary with the COUNTRY identifier is created in the database. The dictionary is created in MDM repository with the RDS identifier. Additional integer attribute Code is created in MDM dictionary. The elements with following values of attributes are also created in MDM dictionary:
Code - 1; Name - "Russia".
Code - 2; Name - "USA".
Element with a key 69 is created in dictionary of measure units. Annual frequency is used in the time series database.
Function OpenArrayProvider: IDatasetDataArrayProvider;
Var
ArrayProvider: IDatasetDataArrayProvider;
Arr: Array Of Variant;
TField: ITableField;
Row: Integer = 1000; //Quantity of lines with data
Begin
Arr := New Variant[Row, 5];
Arr[0, 0] := 1; Arr[0, 1] := "Russia"; Arr[0, 2] := 69; Arr[0, 3] := "1997A1"; Arr[0, 4] := 11.178;
Arr [1, 0: =1] ; Arr [1, 1] : = "Russia"; Arr [1, 2: =69] ; Arr [1, 3] : = "1998A1"; Arr [1, 4: =20] .123;
Arr [2, 0: =1] ; Arr [2, 1] := "Russia"; Arr [2, 2: =69] ; Arr [2, 3] : = "1999A1"; Arr [2, 4: =21] .67;
Arr [3, 0: =1] ; Arr [3, 1] := "Russia"; Arr [3, 2: =69] ; Arr [3, 3] : = "2000A1"; Arr [3, 4: =22] .458;
Arr [4, 0: =1] ; Arr [4, 1] := "Russia"; Arr [4, 2: =69] ; Arr [4, 3] : = "2001A1"; Arr [4, 4: =23] .178;
Arr [5, 0: =2] ; Arr [5, 1] := "USA"; Arr [5, 2:=69] ; Arr [5, 3] : = "1997A1"; Arr [5, 4:=22] .167;
Arr [6, 0: =2] ; Arr [6, 1] := "USA"; Arr [6, 2:=69] ; Arr [6, 3] := "1998A1"; Arr [6, 4:=25] .12;
//Other data...
ArrayProvider := New DatasetDataArrayProvider.Create;
ArrayProvider.AddField("Code", DbDataType.Integer);
ArrayProvider.AddField("Country", DbDataType.String);
ArrayProvider.AddField("Units", DbDataType.Integer);
ArrayProvider.AddField("Year", DbDataType.String);
ArrayProvider.AddField("Value", DbDataType.Float);
ArrayProvider.AttachArray(Arr);
Return ArrayProvider;
End Function OpenArrayProvider;
Sub LoadDataFromArray;
Var
Mb: IMetabase;
RubDesc, NSIDesc: IMetabaseObjectDescriptor;
CubeMetaLoader: ICubeMetaLoader;
CrInfo: IMetabaseObjectCreateInfo;
Obj: IMetabaseObject;
ObjDesc: IMetabaseObjectDescriptor;
Bindings: ICubeMetaLoaderBindings;
Binding: ICubeMetaLoaderBinding;
Begin
Mb := MetabaseClass.Active;
RubDesc := Mb.ItemById("FC");
NSIDesc := Mb.ItemById("RDS");
// Object of import
CrInfo := Mb.CreateCreateInfo;
CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_CUBEMETALOADER;
CrInfo.Id := "CUBEMETALOADER";
CrInfo.Permanent := False;
CrInfo.Parent := RubDesc;
ObjDesc := Mb.CreateObject(CrInfo);
Obj := ObjDesc.Edit;
CubeMetaLoader := Obj As ICubeMetaLoader;
//Binding of attributes
Bindings := CubeMetaLoader.Bindings;
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Attribute;
Binding.Attribute := "COUNTRY";
Binding.FieldType := CubeMetaLoaderFieldType.Index;
Binding.Field := "0";
Binding.CheckField := "1";
Binding.Dimension := Mb.ItemByIdNamespace("COUNTRY", NsiDesc.Key).Bind As IDimensionModel;
Binding.Index := "UNIQUEKEY";
Binding.KeyAttribute := "KEY";
Binding.NameAttribute := "NAME";
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Unit;
Binding.FieldType := CubeMetaLoaderFieldType.Index;
Binding.Field := "2";
Binding.Dimension := Mb.ItemByIdNamespace("UNITS", NSIDesc.Key).Bind As IDimensionModel;
Binding.Index := "PRIMARY_INDEX";
Binding.KeyAttribute := "KEY";
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Calendar;
Binding.CalendarOptions.Levels := DimCalendarLevelSet.Year;
Binding.ByColumns := False;
Binding.CalendarDateFormat := "$Year$A1";
Binding.FieldType := CubeMetaLoaderFieldType.Index;
Binding.Field := "3";
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Value;
Binding.FieldType := CubeMetaLoaderFieldType.Index;
Binding.Field := "4";
Binding := Bindings.Add;
Binding.BindingType := CubeMetaLoaderBindingType.Attribute;
Binding.Attribute := "DL";
Binding.FieldType := CubeMetaLoaderFieldType.ConstValue;
Binding.FieldValue := DimCalendarLevel.Year;
//Options of loader
CubeMetaLoader.LoadType := CubeMetaLoaderLoadType.CreateAndUpdate;
CubeMetaLoader.Rubricator := RubDesc.Bind As IRubricator;
CubeMetaLoader.Data := OpenArrayProvider;
CubeMetaLoader.LoadData;
End Sub LoadDataFromArray;
The OpenArrayProvider function implements the custom data source loading the data from array. At LoadDataFromArray procedure execution the loader of time series is created. Parameters of binding attributes are set up, and also the custom data source is specified as data source. After that data is loaded.
Executing the example requires that the repository contains a time series database with the FC identifier. The attribute referring to MDM dictionary with the COUNTRY identifier is created in the database. The dictionary is created in MDM repository with the RDS identifier. Additional integer attribute Code is created in MDM dictionary. Also elements with following values of attributes are created in MDM dictionary:
Code - 1; Name - "Russia".
Code - 2; Name - "USA".
Element with a key 69 is created in dictionary of measure units. Annual frequency is used in the time series database.
Public Class Program
Shared Function OpenArrayProvider(): IDatasetDataArrayProvider;
Var
ArrayProvider: IDatasetDataArrayProvider;
Arr: Array;
TField: ITableField;
Row: Integer = 1000; //Quantity of rows with data
Begin
Arr := New Object[5, Row];
Arr[0, 0] := 1; Arr[0, 1] := "Russia"; Arr[0, 2] := 69; Arr[0, 3] := "1997A1"; Arr[0, 4] := 11.178;
Arr[1, 0] := 1; Arr[1, 1] := "Russia"; Arr[1, 2] := 69; Arr[1, 3] := "1998A1"; Arr[1, 4] := 20.123;
Arr[2, 0] := 1; Arr[2, 1] := "Russia"; Arr[2, 2] := 69; Arr[2, 3] := "1999A1"; Arr[2, 4] := 21.67;
Arr[3, 0] := 1; Arr[3, 1] := "Russia"; Arr[3, 2] := 69; Arr[3, 3] := "2000A1"; Arr[3, 4] := 22.458;
Arr[4, 0] := 1; Arr[4, 1] := "Russia"; Arr[4, 2] := 69; Arr[4, 3] := "2001A1"; Arr[4, 4] := 23.178;
Arr[5, 0] := 2; Arr[5, 1] := "USA"; Arr[5, 2] := 69; Arr[5, 3] := "1997A1"; Arr[5, 4] := 22.167;
Arr[6, 0] := 2; Arr[6, 1] := "USA"; Arr[6, 2] := 69; Arr[6, 3] := "1998A1"; Arr[6, 4] := 25.12;
//Other data...
ArrayProvider := New DatasetDataArrayProviderClass();
ArrayProvider.AddField("Code", DbDataType.ddtInteger);
ArrayProvider.AddField("Country", DbDataType.ddtString);
ArrayProvider.AddField("Units", DbDataType.ddtInteger);
ArrayProvider.AddField("Year", DbDataType.ddtString);
ArrayProvider.AddField("Value", DbDataType.ddtFloat);
ArrayProvider.AttachArray(Arr);
Return ArrayProvider;
End Function OpenArrayProvider;
[STAThread]
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
RubDesc, NSIDesc: IMetabaseObjectDescriptor;
CubeMetaLoader: ICubeMetaLoader;
CrInfo: IMetabaseObjectCreateInfo;
Obj: IMetabaseObject;
ObjDesc: IMetabaseObjectDescriptor;
Bindings: ICubeMetaLoaderBindings;
Binding: ICubeMetaLoaderBinding;
Begin
Mb := Params.Metabase;
RubDesc := Mb.ItemById["FC"];
NSIDesc := Mb.ItemById["RDS"];
// Object of import
CrInfo := Mb.CreateCreateInfo();
CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_CUBEMETALOADER As Int32;
CrInfo.Id := "CUBEMETALOADER";
CrInfo.Permanent := False;
CrInfo.Parent := RubDesc;
ObjDesc := Mb.CreateObject(CrInfo);
Obj := ObjDesc.Edit();
CubeMetaLoader := Obj As ICubeMetaLoader;
//Attributes binding
Bindings := CubeMetaLoader.Bindings;
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtAttribute;
Binding.Attribute := "COUNTRY";
Binding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;
Binding.Field := "0";
Binding.CheckField := "1";
Binding.Dimension := Mb.ItemByIdNamespace["COUNTRY", NsiDesc.Key].Bind() As IDimensionModel;
Binding.Index := "UNIQUEKEY";
Binding.KeyAttribute := "KEY";
Binding.NameAttribute := "NAME";
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtUnit;
Binding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;
Binding.Field := "2";
Binding.Dimension := Mb.ItemByIdNamespace["UNITS", NSIDesc.Key].Bind() As IDimensionModel;
Binding.Index := "PRIMARY_INDEX";
Binding.KeyAttribute := "KEY";
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtCalendar;
Binding.CalendarOptions.Levels := DimCalendarLevelSet.dclsYear;
Binding.ByColumns := False;
Binding.CalendarDateFormat := "$Year$A1";
Binding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;
Binding.Field := "3";
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtValue;
Binding.FieldType := CubeMetaLoaderFieldType.cmlftIndex;
Binding.Field := "4";
Binding := Bindings.Add();
Binding.BindingType := CubeMetaLoaderBindingType.cmlbtAttribute;
Binding.Attribute := "DL";
Binding.FieldType := CubeMetaLoaderFieldType.cmlftConstValue;
Binding.FieldValue := DimCalendarLevel.dclYear;
//Loader settings
CubeMetaLoader.LoadType := CubeMetaLoaderLoadType.cmlltCreateAndUpdate;
CubeMetaLoader.Rubricator := RubDesc.Bind() As IRubricator;
CubeMetaLoader.Data := OpenArrayProvider();
CubeMetaLoader.LoadData();
End Sub;
End Class;
The OpenArrayProvider function implements the custom data source loading the data from array. At procedure Main execution the loader of time series is created. Parameters of binding attributes are set up, and also the custom data source is specified as data source. After that the loading of data is performed.
See also: