Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
Yes, Always we should eye to avoid null pointer exception @uganesh
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"
Adding to that am assuming in columns a and column b we have only yes, no and null, Please confirm it
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
Yes, Always we should eye to avoid null pointer exception @uganesh
I am currently testing this expression.
Crossing my fingers it works..
If it worked , please make this topic as resolved. It helps others.