• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » tMap Expression Builder - IF-ELSE statements

#1 2010-07-29 19:09:06

talend_newbie
New member
Registered: 2010-07-28
Posts: 5

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!

Offline

#2 2010-07-30 02:42:45

alevy
Member
Registered: 2009-11-20
Posts: 1486

Re: tMap Expression Builder - IF-ELSE statements

Certainly is.  Use standard Java syntax: <boolean test condition>?<then expression>:else expression.  For example:

Code:

row1.myKey.equals("FirstValue")?1:0

Offline

#3 2012-10-22 10:35:52

kp.balaji123
Guest

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.

#4 2012-10-22 11:47:04

shong
Talend team
Registered: 2007-08-29
Posts: 10303
Website

Re: tMap Expression Builder - IF-ELSE statements

kp.balaji123 wrote:

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.


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#5 2013-02-06 19:09:54

Rozie
Member
Registered: 2012-09-27
Posts: 86

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!

Last edited by Rozie (2013-02-06 19:11:37)

Offline

#6 2013-02-06 23:04:58

alevy
Member
Registered: 2009-11-20
Posts: 1486

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

Offline

#7 2013-02-07 02:36:17

Rozie
Member
Registered: 2012-09-27
Posts: 86

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!

Offline

#8 2013-02-07 03:05:12

alevy
Member
Registered: 2009-11-20
Posts: 1486

Re: tMap Expression Builder - IF-ELSE statements

What's the error?!

Offline

#9 2013-02-07 03:56:18

Rozie
Member
Registered: 2012-09-27
Posts: 86

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 smile

Last edited by Rozie (2013-02-07 04:47:02)

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » tMap Expression Builder - IF-ELSE statements

Board footer

Powered by FluxBB