tMap conditional formula

Highlighted
Six Stars

tMap conditional formula

I am trying to write a condition in my tMap translation.  It is giving me an error when trying to run.  Essentially, I have a required field I am trying to populate on the Output.  From the input, I first want to check one of the columns for null.  If it is null, I want to use a different column to populate output.  Here is what I have written, not sure what I am missing:

 

row1.Field1 = null ? row1.Field2 : row1.Field1


Accepted Solutions
Highlighted
Six Stars

Re: tMap conditional formula

@manishchokkaram @nikhilthampi @akumar2301   Thank you all for your help!

I made a few adjustments and got it to work.  Here is the final expression I used:

row1.NAME != null && row1.NAME.trim().length() != 0 ? row1.NAME : row1.NUM

 

I really appreciate all of  your input.  I'm new to Talend and this is helpful.  This board is great. I will be now be a longtime user.

View solution in original post


All Replies
Highlighted
Six Stars

Re: tMap conditional formula

Also, I have tried comparing using = and ==.   Either way, I am getting an error when the first field is blank and it is not populating it the 2nd field. 

Highlighted
Eleven Stars

Re: tMap conditional formula

(row1.Field1 == null || row1.Field1.trim().length() == 0 )? row1.Field2 : row1.Field1

 
 
 
Regards
Abhishek KUMAR
Highlighted
Nine Stars

Re: tMap conditional formula

@steeld95  the one which @akumar2301  sent will work, even i used it before, specially when we have empties other then null it will be very helpful

Highlighted
Six Stars

Re: tMap conditional formula

Thank you @akumar2301.  It is now giving me a different error.  It is saying:

Token<END-OF-STATEMENT> was not valid. Valid tokens: ? : <FLOAT> <BIGINT> <DECIMAL>

 

It is all string fields.  The input fields are stings and the output field is a string.   

 

I appreciate your help!

Highlighted
Nine Stars

Re: tMap conditional formula

(row1.Field1 == null || StringHandling.LEN(row1.Field1)== 0 )? row1.Field2 : row1.Field1

Highlighted
Eleven Stars

Re: tMap conditional formula

 

Error looks unrelated.Can you please verify and confirm that , this error comes only with above expression.

Are you using any database Query before. usually these errors are databse related.

 

can you please give your job screenshots.

Regards
Abhishek KUMAR
Highlighted
Nine Stars

Re: tMap conditional formula

@akumar2301  the above function i mentioned just now may work, let @steeld95 try it and let us know

 

Please dont forget to give kudos and accept solution if it worked @steeld95 

Highlighted
Employee

Re: tMap conditional formula

Hi,

 

    Seems you are trying to load the String value to a database like DB2 where the data is in different format.

 

    Could you please share the screen shot of the job flow and the component where it is erroring out? There could be some data type mismatch but getting the full error and screen shot of the job only can help us to dig further.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

Highlighted
Six Stars

Re: tMap conditional formula

They are both actually strings.  I am trying to move a string to a string.  I have definitely narrowed it down to this translation, because if I just put in default text in that field to test it, it runs the job with no errors.   I have confirmed, both fields in the input and the output are strings. Strange behavior. 

Highlighted
Eleven Stars

Re: tMap conditional formula

Can you print field1 and field2 as separate cols and check no error their.
Regards
Abhishek KUMAR
Highlighted
Employee

Re: tMap conditional formula

Hi,

 

   Could you please share the screen shots of the job flow, problematic component and schema details?

 

   Please also share the target DB. It should be something minor. Once we see the flow, we will get better idea.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

Highlighted
Six Stars

Re: tMap conditional formula

@manishchokkaram @nikhilthampi @akumar2301   Thank you all for your help!

I made a few adjustments and got it to work.  Here is the final expression I used:

row1.NAME != null && row1.NAME.trim().length() != 0 ? row1.NAME : row1.NUM

 

I really appreciate all of  your input.  I'm new to Talend and this is helpful.  This board is great. I will be now be a longtime user.

View solution in original post

Highlighted
Eleven Stars

Re: tMap conditional formula

Weird But Good.

Regards
Abhishek KUMAR
Highlighted
Nine Stars

Re: tMap conditional formula

@steeld95 Oh Am almost close, thanks for updating the result

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog