Testing Logic is probably the most-used job design in TALEND PROGRAMMING and is used to ensure that a snippet of new code is not influenced by external factors within a large and complex job. This simple recipe shows how this can easily be achieved.
If you would like to Enrich your career with a Talend certified professional, then visit Mindmajix - A Global online training platform: “Talend Certification Training” Course. This course will help you to achieve excellence in this domain.
Getting ready
Open the jo_cook_ch10_0140_logicTest job.
How to do it…
The steps for testing logic are as follows:
customer.age >= 21 && customer.country.equals("UK") ? true : customer.age >= 18
&& !customer.country.equals("UK") ? true : false
How it works…
In this example, we are testing an age limit; 21 or over is valid for the UK, 18 or over is valid for the rest of the world. In tFixedFlowInput, we defined a set of test values that would prove that the logic test in tMap is working correctly.The tLogRow component, then allows us to see the inputs and the corresponding results.
There’s more…
This example is great for testing new rules, and especially for testing new code routines prior to adding to a complex job. It is quick to create, and the tFixedFlowInput component allows us to build a controlled set of test data that should test all return values, thus giving us confidence in the correctness of the new code or code routine.
Frequently Asked TALEND Interview Questions & Answers
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 their settings. Here, let us see one of the ways to 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 that something went wrong, so that the person running the job will be able to fix the issue.
1. Create a new Job;
2. Add 3 components
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;
3. Create a Delimited file (.csv) and make sure that for one of the columns the value is null;
4. 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 equals to null for a particular column, then print a message to the console log and terminate the job.
5. 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.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Talend Training | Nov 23 to Dec 08 | View Details |
Talend Training | Nov 26 to Dec 11 | View Details |
Talend Training | Nov 30 to Dec 15 | View Details |
Talend Training | Dec 03 to Dec 18 | View Details |
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.