[resolved] Question about TJavaRow comparing string values.

One Star

[resolved] Question about TJavaRow comparing string values.

I need to compare global variable value with string value. And if condition JOB must be stopped.
I did this on TJavaRow:
System.out.println("My value " + globalMap.get("IsLocked")) ;
if (globalMap.get("IsLocked") == "N") {System.out.println("Then");}
else {throw new RuntimeException("----Raise error-------");};
Why condition doesn't work? It raises error while Println returns " My value N".
Global variable type is Char.

Accepted Solutions
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Just add a tJavaRow after each tFilterRow to compute the number of rows using a dedicated global variable.
This way, you may avoid to call the txxxxxOutput components when the corresponding number of rows is equal to 0.
This is a solution, many other may exist as TOS is very adaptable.
TRF

All Replies
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Hi,
Use the Java equals() function instead of the == operator for string comparisons.
( (String)globalMap.get("isLocked") ).equals("N")
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Hi walkerca,
now code looks like:
System.out.println("My value " + globalMap.get("IsLocked")) ;
if (( (String)globalMap.get("IsLocked") ).equals("N")) {System.out.println("Then");}
//else {System.out.println("Then2");};
else {throw new RuntimeException("----Raise error-------");};
But i get error:
Exception in component tJavaRow_2
java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
When i remove (String) option it doesn't compares values in right way. I mean runs "---- Raise error ---" while value is "N" Println returns - My value N
I tried IsLocked in MSSQLInput Edit schema change DB type between CHAR and VARCHAR but it didn't help..
EDIT : need to change Type to String in Edit Schema.
Thanks.
One Star

Re: [resolved] Question about TJavaRow comparing string values.

try updating your if condition to this.
if (globalMap.get("IsLocked").toString().equals("N")){ System.out.println("Then"); }
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Was isLocked set with a 'N' rather than "N" (single versus double quotes)? Make sure that it was actually loaded in the globalMap as a String.
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Hii everyone,
I am very new to talend. I have a flat file in .csv form. In the flat file there is a field which can have values like lms/spar/max. It is mandatory that at least once these three names has to occur in the flat-file. If the File don't have any one of this option, I have to send a mail. What should I do?
I tried something like this:
FileInputDelimited -> tjavarow ->runif -> tsendmail
I tried using flag to check if any of these option are not present. But its showing error as 'flag cannot be resolved to a variable'!
please tell me a way out to solve this problem.
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Hi,
Use a tFilter to get records with one of the three values mls/spar/max.
If no row goes to the the filtered output, then no records contains the desired values and you can go with tSendMail.
No tJavaRow required for this.
Regards,
TRF
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Hi,
Thanks a bunch TRF for your suggestion. But I am already using three filters to send the LMS/SPAR/MAX into its respective database table. So now how should I check whether there is data passing through it or not. 
my whole process looks like this
FileInputDelimited -> tmap -> tfilterrow -> lms data into lms database 
                                 |_ -> tfilterrow -> spar data into spar database 
                                 |_ -> tfilterrow -> max data into max database 
Now how should I add a check in tfilter row to check if no row is passing through it into the database.
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Just add a tJavaRow after each tFilterRow to compute the number of rows using a dedicated global variable.
This way, you may avoid to call the txxxxxOutput components when the corresponding number of rows is equal to 0.
This is a solution, many other may exist as TOS is very adaptable.
TRF
One Star

Re: [resolved] Question about TJavaRow comparing string values.

Hi,
I wanted the flag..I need to use it in the further process. 
My Code which I am inserting in tjavarow  is as below:
int flag1=0, flag2=0;
if (output_row.OU_CODE.equals("LMS"))
flag1 = 1;
else (output_row.OU_CODE.equals("SPAR"))
flag2 = 1;
But tjavarow is giving me  errors like.. 



Please help me write this code well so that tjavarow wont give me errors. Also After tjava row I have runif condition which will check if flag1==0 || flag2==0 and then send a mail. 

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download