logical Testing the most used pattern in Talend

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:

  • In tFixedFlowInput, tick the box labeled Use Inline Table.
  • Add the values, as shown in the following screenshot:
  • In the tMap, add a new field to the output named ageCheckValid, and populate it with the following code:
customer.age >= 21 && customer.country.equals("UK") ? true : customer.age >= 18  
          && !customer.country.equals("UK") ? true : false
  • Run the job to see the results of the test.

MindMajix Youtube Channel

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

Killing a job from within tJavaRow

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 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.

Validation Process

1. Create a new Job;
2. Add 3 components

  • “tFileInputDelimited”;
  • “tJavaRow”;
  • “tLogRow”;
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.

Explore TALEND Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

Job Support Program

Online Work Support for your on-job roles.

jobservice

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:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Talend TrainingNov 23 to Dec 08View Details
Talend TrainingNov 26 to Dec 11View Details
Talend TrainingNov 30 to Dec 15View Details
Talend TrainingDec 03 to Dec 18View Details
Last updated: 03 Apr 2023
About Author

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.

read less