EventId: String;
EventId: string;
The EventId property determines identifier of the event called on occurring ETL task execution error.
To determine the method of handling the errors, which may occur on data loading, use the IEtlPlainDataCopy.ActionOnProblem property.
Executing the example requires:
An ETL task with the ETL identifier and a table with the TBL identifier in the repository.
Fields of the table used in the example:
KEY. Field of integer type.
COUNTRY_NAME. Field of string type.
OWNER. Field of string type.
The C:\ETL_imp.txt text file in the file system.
The first four lines of a text file used in the example:
"Key","Country Name","Owner"
512,"Afghanistan",3
914,"Albania",1
612,"Algeria",2
Add links to the Metabase, Etl, Dt, Db, Andy, Drawing system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Task: IEtlTask;
CopyObj: IEtlPlainDataCopy;
FProvider: IDtTextProvider;
Tab: IDatasetModel;
FConsumer: IDtMetabaseConsumer;
ProvFields, ConsFields: IDtFieldDefinitions;
i: Integer;
WxConsumer: IWxRectangle;
WxETLConsumer: IWxEtlObject;
Begin
MB := MetabaseClass.Active;
Task := MB.ItemById("ETL").Edit As IEtlTask;
// Create an object that copies data
CopyObj := Task.Create(EtlObjectType.PlainDataCopy) As IEtlPlainDataCopy;
CopyObj := CopyObj.Edit;
// Set up data source parameters
FProvider := New DtTextProvider.Create As IDtTextProvider;
FProvider.File := "C:\ETL_imp.txt";
FProvider.DelimitedColumnDelimiter := ",";
FProvider.HeaderRow := 1;
FProvider.FormatType := DtTextFormatType.Delimited;
FProvider.RangeHasHeader := True;
FProvider.RangeFirstRow := 1;
COpyObj.Provider := FProvider;
// Set up data consumer parameters
FConsumer := New DtMetabaseConsumer.Create;
Tab := MB.ItemById("TBL").Edit As IDatasetModel;
FConsumer.Dataset := Tab;
CopyObj.Consumer := FConsumer;
// Link source and consumer data
ProvFields := FProvider.Fields;
ConsFields := FConsumer.Fields;
CopyObj.AutoLink;
For i := 0 To ProvFields.Count - 1 Do
If Not CopyObj.IsLinked(ProvFields.Item(i).Name, ConsFields.Item(i).Name) Then
CopyObj.AddLink(ProvFields.Item(i).Name, ConsFields.Item(i).Name);
End If;
End For;
// Clear data consumer
CopyObj.ClearConsumer := True;
// Process errors
CopyObj.ActionOnProblem := EtlActionOnProblem.DiscardRecordsInTransaction;
CopyObj.SaveInvalidRecs := True;
CopyObj.InvalidRecsFileName := "Errors";
CopyObj.UseStopLimit := True;
CopyObj.StopLimit := 2;
CopyObj.CommitCount := 10;
CopyObj.EventId := "CUSTOM_EVENT";
// Save object that copies data
CopyObj.Save;
// Create a visual object
WxConsumer := Task.Workspace.CreateRectangle;
WxETLConsumer := New WxEtlObject.Create;
WxETLConsumer.EtlObject := CopyObj;
WxConsumer.Style.TextPosition := WxTextPosition.Bottom;
WxConsumer.Style.PictureMarginTop := -10;
WxConsumer.PinPosition := New GxPointF.Create(50, 50);
WxConsumer.Extension := WxETLConsumer As IWxShapeExtension;
// Save ETL task object
(Task As IMetabaseObject).Save;
End Sub UserProc;
After executing this example a new object that copies data is created in ETL task. Copying is performed from a text file into a repository table. The following settings are determined for the Copy Data object:
Fields of source and consumer are linked automatically.
If any link between fields of a source and consumer cannot be created automatically, it is added manually.
If errors occur while loading, records within one transaction will be ignored.
If errors occur, all skipped records on executing the task are saved into the Errors file.
If more than two errors occur, task execution is stopped.
10 records could be processed within one transaction.
If errors occur on task execution, the Starting Loading event is called.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Etl;
Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Andy;
Imports Prognoz.Platform.Interop.Drawing;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
Task: IEtlTask;
CopyObj: IEtlPlainDataCopy;
FProvider: IDtTextProvider;
Tab: IDatasetModel;
FConsumer: IDtMetabaseConsumer;
ProvFields, ConsFields: IDtFieldDefinitions;
i: Integer;
WxConsumer: IWxRectangle;
WxETLConsumer: IWxEtlObject;
OutPoint: GxPointF = New GxPointFClass();
Begin
MB := Params.Metabase;
Task := MB.ItemById["ETL"].Edit() As IEtlTask;
// Create an object that copies data
CopyObj := Task.Create(EtlObjectType.eotPlainDataCopy) As IEtlPlainDataCopy;
CopyObj := CopyObj.Edit();
// Set up data source parameters
FProvider := New DtTextProvider.Create() As IDtTextProvider;
FProvider.File := "C:\temp\ETL_imp.txt";
FProvider.DelimitedColumnDelimiter := ",";
FProvider.HeaderRow := 1;
FProvider.FormatType := DtTextFormatType.tftDelimited;
FProvider.RangeHasHeader := True;
FProvider.RangeFirstRow := 1;
COpyObj.Provider := FProvider;
// Set up data consumer parameters
FConsumer := New DtMetabaseConsumer.Create();
Tab := MB.ItemById["TBL"].Edit() As IDatasetModel;
FConsumer.Dataset := Tab;
CopyObj.Consumer := FConsumer;
// Link source and consumer data
ProvFields := FProvider.Fields;
ConsFields := FConsumer.Fields;
CopyObj.AutoLink();
For i := 0 To ProvFields.Count - 1 Do
If Not CopyObj.IsLinked(ProvFields.Item[i].Name, ConsFields.Item[i].Name) Then
CopyObj.AddLink(ProvFields.Item[i].Name, ConsFields.Item[i].Name);
End If;
End For;
// Clear data consumer
CopyObj.ClearConsumer := True;
// Process errors
CopyObj.ActionOnProblem := EtlActionOnProblem.aopDiscardRecordsInTransaction;
CopyObj.SaveInvalidRecs := True;
CopyObj.InvalidRecsFileName := "Errors";
CopyObj.UseStopLimit := True;
CopyObj.StopLimit := 2;
CopyObj.CommitCount := 10;
CopyObj.EventId := "CUSTOM_EVENT";
// Save object that copies data
CopyObj.Save();
// Create a visual object
WxConsumer := Task.Workspace.CreateRectangle();
WxETLConsumer := New WxEtlObject.Create();
WxETLConsumer.EtlObject := CopyObj;
WxConsumer.Style.TextPosition := WxTextPosition.wtpBottom;
WxConsumer.Style.PictureMarginTop := -10;
OutPoint := WxConsumer.PinPosition;
OutPoint.Create(50, 50);
WxConsumer.Extension := WxETLConsumer As IWxShapeExtension;
// Save ETL task object
(Task As IMetabaseObject).Save();
End Sub;
See also: