If then else expression in Tmap : ERROR

Highlighted
Five Stars

If then else expression in Tmap : ERROR

Hello,

 

I've search this forum for 2 days to get the syntax for my variable down.

When launching my job however, my tmap is in error.

 

My expression:

 

(in_row.ColumnA.equals ("YES") && in_row.ColumnB("NO")) ? "1":
(in_row.ColumnA.equals("NO") && in_row.ColumnB.equals("YES"))? "2": ""

 

ColumnA and ColumnB are string. And I want to create a new out column that has 3 values  depending on columnA and columnB values: 1, 2 or empty.

 

Can someone give me any pointers on how to proceed from here ?

 

Thank you in advance!


Accepted Solutions
Highlighted
Nine Stars

Re: If then else expression in Tmap : ERROR

Yes, Always we should eye to avoid null pointer exception @akumar2301 

View solution in original post


All Replies
Highlighted
Nine Stars

Re: If then else expression in Tmap : ERROR

initially check either columnA  or columnB not equal to null. As we don't want both nulls in two columns

then

write this expression as per your requirement

(in_row.ColumnA.equals ("YES") && in_row.ColumnB("NO")) ? "1":

"2"

 

Highlighted
Nine Stars

Re: If then else expression in Tmap : ERROR

Adding to that am assuming in columns a and column b we have only yes, no and null, Please confirm it 

Highlighted
Five Stars

Re: If then else expression in Tmap : ERROR

Yes , the values in those columns are either yes, no or null
Highlighted
Nine Stars

Re: If then else expression in Tmap : ERROR

Then you will have mutiple combinations

ColumnA    ColumnB

null         yes

yes         null

null         no

no         null

no         yes

yes        no

no         no

yes       yes

 

Even if you want to populate only the value for your chosen combination before as below, you should one particular value with string you chosen its an empty  string which is fine, but you should check  the condition  columnA  or columnB not equal to null, that means both not equal to null , but its not required if you want to use a specific combination as below you can set all values to empty string

(in_row.ColumnA.equals ("YES") && in_row.ColumnB("NO")) ? "1":
(in_row.ColumnA.equals("NO") && in_row.ColumnB.equals("YES"))? "2"

:

""

But use below 

function , you did not write in_row.columnB.equals("No") may be that caused problem

 

But 

use below function 

(in_row.ColumnA.equalsIgnoreCase("YES") && in_row.ColumnB.equalsIgnoreCase ("NO")) ? "1":
(in_row.ColumnA.equalsIgnoreCase("NO") && in_row.ColumnB.equalsIgnoreCase("YES"))? "2"

:

""

 

Please give kudos if it solves your issue and accept as solution

 

Highlighted
Eleven Stars

Re: If then else expression in Tmap : ERROR

I agree with Manish. Just To avoid null pointer

Use (“yes”).equalIgnoreCase(row1....)

Instead of
in_row.ColumnA.equalsIgnoreCase("YES")

In this case if any of two column is null , output will be “”
Regards
Abhishek KUMAR
Highlighted
Nine Stars

Re: If then else expression in Tmap : ERROR

Yes, Always we should eye to avoid null pointer exception @akumar2301 

View solution in original post

Highlighted
Five Stars

Re: If then else expression in Tmap : ERROR

I am currently testing this expression. 

 

Crossing my fingers it works..

Highlighted
Eleven Stars

Re: If then else expression in Tmap : ERROR

If it worked , please make this topic as resolved. It helps others.

Regards
Abhishek KUMAR

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