After setting up a validation rule, you can apply it on your Job designs. For example, let's apply a basic check for correct values validation rule when reading a database table. This scenario is based on the basic check validation rule created in Designing a Job. For more information about this rule, see Basic rule.
Setting up the Job environment
From the Palette, drop these components onto the design workspace: a database input component, here tMysqlInput, that you will read and check the values of, two tFileOutputDelimited components to extract the valid data in one file and the rejected ones in another file, and a tJava component to display the number of lines processed in the console.
Connect the input database component to the first tFileOutputDelimited component using a Row > Main link, and connect the tMysqlInput component to the tJava component with a Trigger > OnSubjobOk link.
You will be able to create the reject link between the tMysqlInput and the second tFileOutputDelimited component only when you will have applied the validation rule to the tMysqlInput component.
Configuring the input component
Double-click the tMysqlInput component to display its Basic settings.
Select Repository as Property type and click the three-dot button next to the field to retrieve the connection properties that corresponds to the metadata you want to check.
Select Repository from the Schema drop down list and click the three-dot button next to the field to retrieve the schema that corresponds to your database table.
Click the three-dot button next to the Table field to select the table to check.
Click Guess Query to automatically retrieve the query corresponding to the table schema.
Applying the validation rule and creating a reject link
As the On select option was selected for this validation rule, the validation rule must be applied to the input component.
Click the Validation Rules tab of the tMysqlInput Component view.
Select the Use an existing validation rule check box to apply the validation rule to the component.
In the Validation Rule Type list, select Repository and click the [...] button to select the validation rule from the [Repository Content] window.
Right-click tMysqlInput, select Row> Reject in the menu and drag to the second tFileOutputDelimited component to create a reject link between the two components.
If you have enabled the Reject link option for this validation rule you can retrieve the rejected data to a reject flow.
Configuring the output components and viewing the Job execution result
Double-click the first tFileOutputDelimited component to display its Basic settings.
In the File Name field, specify the path and name of the file to write with the valid data.
Define the row and field separators in the corresponding fields.
Select the Include Header check box to include column headers in the output data.
Repeat the steps above on the second tFileOutputDelimited component to configure the output of the rejected data.
Double-click the tJava component to display its Basic settings.
In the Code field, type in the code that will display the number of updated, inserted and rejected lines processed:
System.out.println("Valid data: "+((Integer)globalMap.get("tFileOutputDelimited_1_NB_LINE"))+"\nRejected data: "+((Integer)globalMap.get("tFileOutputDelimited_2_NB_LINE")));
Save your Job and press F6 to execute it.
Valid data is outputted in the first delimited file and rejects to the second, and the console displays the number of valid lines and the number of rejects processed in the Job.