User Case
There are multiple ways to stop a job in Talend. You could use “if” trigger statements combined with “tDie”, some components have a die on error tick boxes in there settings. This article will describe one of the ways kill/terminate a Talend Studio job based on an input file row value.
Let’s say you are black boxing a Talend job for a client and you know based on experience that the client does not always provide the most accurate input files. Some of the rows that must be NOT NULL for the job to run successfully aren’t always provided. Unfortunately you cannot substitute those empty rows with dummy data (according to your job logic), so you have to kill the job and inform the client what something went wrong, so that the person running the job will be able to fix the issue.
Validation Process
- Create a new Job;
- Add 3 components
- “tFileInputDelimited”;
- “tJavaRow”;
- “tLogRow”;
- Create a Delimited file (.csv) and make sure that for one of the columns the value is null;
- In “tJavaRow” add code similar to:
output_row.columnName1= input_row.columnName1; output_row.columnName2 = input_row.columnName2; output_row.columnName3 = input_row.columnName3; if (output_row.columnName4 == null) { System.out.println("Error: " + output_row.columnName4 + " is null"); System.exit(99); } else { output_row.columnName4 = input_row.columnName4; } output_row.columnName5 = input_row.columnName5;
Note: columnName[1,2,3,4,5] – the names of the columns you’ve specified in your Delimited file. If row value is equals to null for a particular column, then print a message to the console log and terminate the job.
- Run the job (if in your delimited file the column that you are evaluating has a null the job will be terminated);
This simple approach can reduce the amount of Talend components used in the Job while providing a way to evaluate the input file.
0 Comments