Two Stars

tMap Expression Builder - IF-ELSE statements

Hi folks,
Just wondering if it is possible to create if-else statements in the tMap expression builder. If you could give some examples it would be much appreciated.
Thank you in advance!
10 REPLIES
Seven Stars

Re: tMap Expression Builder - IF-ELSE statements

Certainly is. Use standard Java syntax: <boolean test condition>?<then expression>:else expression. For example:
row1.myKey.equals("FirstValue")?1:0
One Star

Re: tMap Expression Builder - IF-ELSE statements

Thanks. I was also looking for this and it worked fine. Is there a reference for all these syntax. I dont find it in the user guide or reference guide. I am not a java developer and would like to learn these just for the purpose of using talend effectively.
Community Manager

Re: tMap Expression Builder - IF-ELSE statements

Thanks. I was also looking for this and it worked fine. Is there a reference for all these syntax. I dont find it in the user guide or reference guide. I am not a java developer and would like to learn these just for the purpose of using talend effectively.

Unfortunately, there is no a document for these syntax, but you can always learn these knowledge and experience from Talend forum.
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: tMap Expression Builder - IF-ELSE statements

Hi everyone,
How about this expression at tMap? Could you please help me on the Java syntax?
Example expression at output ColumnC,
if row1.Year_ID < 2009
2000+row2.ColumnA
else
2008+row2.ColumnA
For '+', it's concatenating the value rather than actual add operation.
Your help is very much appreciated!
Seven Stars

Re: tMap Expression Builder - IF-ELSE statements

Presuming that Year_ID and ColumnA are integers, then just:
row1.Year_ID < 2009 ? 2000+row2.ColumnA : 2008+row2.ColumnA
One Star

Re: tMap Expression Builder - IF-ELSE statements

What if..
Year_ID is int
ColumnA is double
output ColumnC is double
row1.Year_ID < 2009 ? 2000+(Integer.parseInt(row2.ColumnA)) : Integer.parseInt(2008+row2.ColumnA)
I tried but it returns error.
Please help me, thanks!
Seven Stars

Re: tMap Expression Builder - IF-ELSE statements

What's the error?!
One Star

Re: tMap Expression Builder - IF-ELSE statements

Hi Alevy,
Sorry, looks like I didn't think hard. tConvertType simply solved my problem.
But I have another problem, what if I have 3 conditions?
Is my design correct?
row1.Year_ID < 2009 ? 2000+row2.F0015 : row1.Year_ID = 2009 ? 2008+row2.F0015 : 2012+row2.F0015

Thanks =)
One Star

Re: tMap Expression Builder - IF-ELSE statements

hello
can anyone please tell me how to divide a data but not all of them 
for example i've the row 'type' witch content so many informations , i want just the 'type' == "stock" i want to have them like they are but when 'type' != "stock" i want to divide all the datas /7
so Stock is for the weekends and the others are for the days  
thanks 
Four Stars

Re: tMap Expression Builder - IF-ELSE statements

hello

i want to do this condition with tmap

Répéter VU_ALIM_TABLEAU_INTEGRATION.DATE + 1 Jusqu’à Date d’expédition - 1


@alevy wrote:
Certainly is. Use standard Java syntax: <boolean test condition>?<then expression>:else expression. For example:
row1.myKey.equals("FirstValue")?1:0


please can anyone help me please and thanks