OnFetch(Var Values: Array): Integer;
Values. The one-dimensional array containing data of single string of data source, that is to be transformed.
The OnFetch method implements the custom transformer of data.
The method should be redetermined in the custom class.
The method is executed for each string of external data source. The Values parameter contains given strings, processed at the moment. This is the array, where data can be changed. The result of method execution should be as follows:
-1 or -2 - Import of data should be stopped immediately.
0 - String is processed, contains correct data and could be imported.
Less than -2, or more than 0 - String contains incorrect data and should be missed.
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 this database. The dictionary is created in MDM repository with the RDS identifier. Additional integer attribute Code is created in MDM dictionary. Annual frequency is used in the time series database.
Class TransformData: Object, IDatasetDataTransform
Public Function OnFetch(Var Values: Array): Integer;
Begin
If <Condition to stop import> Then
Return - 1;
Elseif <Condition to omit record> Then
Return 1;
Else
//Change of data in array Values
Return 0;
End If;
End Function OnFetch;
End Class TransformData;
Function OpenTransformProvider: IDatasetDataTransformProvider;
Var
TransformProvider: IDatasetDataTransformProvider;
Begin
TransformProvider := New DatasetDataTransformProvider.Create;
TransformProvider.Source := <Data source, data of which will be transformed prior to import>;
TransformProvider.Transform := New TransformData.Create;
Return TransformProvider;
End Function OpenTransformProvider;
Sub LoadTransformData;
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 := OpenTransformProvider;
CubeMetaLoader.LoadData;
End Sub LoadTransformData;
The OpenTransformProvider function implements the custom data source loading and transformation of the data from any other source. At procedure LoadTransformData 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. Transformation is performed in the OnFetch method of the TransformData object.
See also: