How to compare two values in If-statement

Six Stars

How to compare two values in If-statement

Hi all, 

 

In the below job, I try to separate rows from a delimited (.csv) file, so that only the rows where "Project_Stadium_Nieuw" and "Project_Stadium_Gisteren" are different, will continue. 

Therefore I first use tFlowToIterate and subsequently put them again in Global Variables, including the Current Iteration number. And then I want to only let through the ones that have these different values. So I use this statement: 

 

(Boolean)(((String)globalMap.get("Project_Stadium_Nieuw"+((Integer)globalMap.get("tFlowToIterate_1_CURRENT_ITERATION")))) != ((String)globalMap.get("Project_Stadium_Gisteren"+((Integer)globalMap.get("tFlowToIterate_1_CURRENT_ITERATION")))))

 

But.. then everything goes through... While I deliberately put some differences in the input file. What am I doing wrong? Or should I set it up differently? 

Please, your advice and tips are more than welcome! Thanks in advance!

 

IfStatement.PNG


Accepted Solutions
Fifteen Stars TRF
Fifteen Stars

Re: How to compare two values in If-statement

Hi,
1st you don't need to compare tFlowToIterate_1_CURRENT_ITERATION with itself. So, you can eliminate this part.
2nd you can't use "!=" or "=" for String comparison. You need to use this syntax:
((String)globalMap.get("Project_Stadium_Nieuw")).equals((String)globalMap.get("Project_Stadium_Gisteren"))

Should works.
However, using a tFilterRow or a tMap with a filter expression would be better (no need to transform flow to global and reverse).

Hope this helps.

TRF

All Replies
Six Stars

Re: How to compare two values in If-statement

Hello,

What is the main purpose of your job ?

I mean what is exactly your input and what do you want in your output ?

Fifteen Stars TRF
Fifteen Stars

Re: How to compare two values in If-statement

Hi,
1st you don't need to compare tFlowToIterate_1_CURRENT_ITERATION with itself. So, you can eliminate this part.
2nd you can't use "!=" or "=" for String comparison. You need to use this syntax:
((String)globalMap.get("Project_Stadium_Nieuw")).equals((String)globalMap.get("Project_Stadium_Gisteren"))

Should works.
However, using a tFilterRow or a tMap with a filter expression would be better (no need to transform flow to global and reverse).

Hope this helps.

TRF
Highlighted
Six Stars

Re: How to compare two values in If-statement

Thanks! I knew it should be something simple! changing the expression to .equals fixed it!

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

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now