Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare String using tMap

Tags:

talend

I am using Talend to prepare dataware. I want to compare the string with the contents of a column using the tMap component and create a variable to store in the DB. The problem is that the == operator does not give the right result (Example: row2.recipient == "text"?"text":"" I always get "") and if I use .equals I get errors when executing.

like image 310
Ahmed BEN MANSOUR Avatar asked Nov 17 '16 16:11

Ahmed BEN MANSOUR


People also ask

Are TMap expressions limited to a single line of code?

Although tMap expressions are limited to a single line of code, the use of the tMap variables, ternary expressions, and code routines do allow very complex mappings to be handled within a single expression. Explore TALEND Sample Resumes!

Why should I use multiple TMap components?

It is recommended that multiple tMap components be used to manage complex transformations so that the code is more easily understood. One of the main limitations of tMap is that the output expressions for transformation are limited to just a single line.

How to create a string based TMap in Talend?

Anyways, you can see all the columns are of string type. Drag and drop the Talend tMap, and connect the tFileInputDelimited Main row to tMap. Double-click on the tMap opens the below window. Please click on the + button to add new output.

How to compare string in Java?

There are three ways to compare String in Java: The String class equals () method compares the original content of the string. It compares values of string for equality. String class provides the following two methods:


1 Answers

You will get error if row2.recipient is null, and "==" should not be used when comparing strings. Correct syntax would be :

"text".equals(row2.recipient)?"text":""

Then you will prevent NullPointerExceptions.

like image 116
Corentin Avatar answered Oct 07 '22 12:10

Corentin