One Star

[resolved] how to check for string null value in tMap

Input is csv file where all fields in schema are defined as string. Some values may be null but need to be handled.
For example, the DIRECTORID field may be empty in the csv input. The target field DIRECTOR_ID in the database is BigDecimal which will be set to zero if the source value is null or empty.
To test, I have used a log row which has fields with String data type:
tFileInputDelimited ----> tMap -----> tLogRow
(ParsedData)

Tried to use the following:
1) ParsedData.DIRECTORID == null ? "0": ParsedData.DIRECTORID
2) ParsedData.DIRECTORID == "" ? "0": ParsedData.DIRECTORID
I was expecting a "0" when the ParsedData.DIRECTORID was empty but got nothing instead.
What am I doing wrong?
Thanks.
p.s. I tried posting an image but it just won't post....
sample source data where field separator is "~;" and row separator is "~\n" (without the quotes) :
1718~;19~;MA~;340~;Goodwin, Steve~
1718~;18~;MD~;~;,~
1718~;5~;MI~;203~;Pueppke, Steven G.~
schema (all String datatype):
TRACKID
STATIONID
STATIONNAME
DIRECTORID
DIRECTORNAME
The second row has empty DIRECTORID and "," value for DIRECTORNAME.
The resulting row in the log (from the console) is:
1718|19|MA|340|Goodwin, Steve
1718|18|MD||,
1718|5|MI|203|Pueppke, Steven G.
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] how to check for string null value in tMap

== only works for testing null object instance or primitive types (int, short, long, boolean, ...).
"String" isn't a primitive type, so you have to use the methods equals() to compare 2 Strings.
8 REPLIES
One Star

Re: [resolved] how to check for string null value in tMap

(ParsedData.DIRECTORID == null || ParsedData.DIRECTORID.equals("")) ? "0" : ParsedData.DIRECTORID
One Star

Re: [resolved] how to check for string null value in tMap

Morbo, that seems to have worked. So I take it that the expression with the "==null" did not apply in this case?
Thanks.
One Star

Re: [resolved] how to check for string null value in tMap

== only works for testing null object instance or primitive types (int, short, long, boolean, ...).
"String" isn't a primitive type, so you have to use the methods equals() to compare 2 Strings.
One Star

Re: [resolved] how to check for string null value in tMap

So you know by now that I am weak in java and oo languages. I have been spoiled by Oracle PLSQL and SQL for many many years. I studied java many years back but never "practiced". It's really great to have helpful people like you.
Thanks again.
Edmund
One Star

Re: [resolved] how to check for string null value in tMap

Np, it's impossible to be efficient in every CS fields, that's why we have to help each other (I suck in PLSQL Smiley Wink).
One Star

Re: [resolved] how to check for string null value in tMap

Hi there,
 
I have a requirement which says-
If Preferred is 'Yes'
    and Email is not null then populate Email
    else populate SecondaryEmail
 
I am using the below given expression in tMap,
 (row2.Preferred == "Yes" && (row2.E_Mail_Number != null || StringHandling.TRIM(row2.E_Mail_Number).length() > 0 || (!row2.E_Mail_Number.isEmpty()))) ? row2.E_Mail_Number : row2.Convio_Email_Number
 
It is not giving me an error, but I am unable to populate any of the Emails
Ten Stars

Re: [resolved] how to check for string null value in tMap

As above, you have to use .equals to compare two String values.  So your first expression would be row2.Preferred.equals("Yes").
The third expression in your E_Mail_Number check is probably superfluous, as checking for a zero length trimmed String will cover the cases covered by .isEmpty.  
One Star

Re: [resolved] how to check for string null value in tMap

How can i populate Null  i database for Boolean value if it is null from tmap. I am able to separate the boolean null value using the condition row1.flag ==null but when i am trying to put null or zero value its saying type mismatch.I am using row1.flag==null ?0 : row1.flag.

Can anyone please help me that what i am doing wrong.