Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Conditional component, simple if true commit else die ...

Hello,

 

I just want to do a simple if statement between 2 integers in order to determine the next action : commit or die. But i don't find out how to manage that simple thing...

 

I use a tDBInput with a select count(*) in order to get my first integer. Then i use a tFixedFlowInput to get the second integer value with this expression ((Integer)globalMap.get("user_customer_NB_LINE_INSERTED")). Now i just need to compare these 2 values, commit if they are equals, die if they are different.

 

0683p000009M0c4.png

Can someone help me achieve this please ?

 

I tried using tMap, tFilterRow, RunIf but didn't find the right way...

 

Thanks,

Guillaume.

Labels (2)
13 Replies
Aukema
Creator
Creator

Hi, 


From your DBoutput component you could do an "OnComponentOk" to the FixedFlowInput component. Then use the runIf trigger from the FixedFlowInput component. Use true to for you commit and false for the tDie. 

 

See attached screenshot

 

0683p000009M0tT.png

 

 

Anonymous
Not applicable
Author

Hi, unfortunately that doesn't seem to work...

First of all, my component called "Verification" is an input and not an output and then I don't understand how that could work because it doesn't seem that we are testing the equality between the two integer values.

Anonymous
Not applicable
Author

That seems to be a quite basic thing, noone knows how i could do that ?

 

Thanks a lot.

Anonymous
Not applicable
Author

Hi,

 

    Could you please try below approach for your use case where you can load the count data from DB to a context variable using a tjavarow?

0683p000009M0mi.png

 

The second subjob will provide the NB_LINE count and in the Run if link, you can join between these two values to do the data comparison operation.

 

If the answer has helped to resolve your query, could you please mark the topic as closed? Kudos are also welcome 🙂

 

Warm Regards,

 

Nikhil Thampi

 

 

 

Anonymous
Not applicable
Author

How can i compare the two values in the Run If link ? I mean how do i get the value from the "tFixedFlowInput" component ?

0683p000009M0tU.png

Anonymous
Not applicable
Author

I did a little bit different and it seems to work ... upside down ...

My values are equals but the test returns me false ... See screenshots below :

 

First of all, my tjavarow component where I define my context variable and display both integer values

0683p000009M0uq.png

 

Then my first RunIf link running tDie if my values are different

0683p000009M0v0.png

 

Now my second RunIf link running a commit job if my values are equals

0683p000009M0v5.png

 

And finally the result i get after the execution of my job ...

0683p000009M0CQ.png

 

As you can see my values are equals but i get the error !

Anonymous
Not applicable
Author

Hi,

 

    Unfortunately, you are trying to create the if condition at wrong area and you are not allowing the entire subjob to be completed. I would suggest you to always use On SubJob Ok trigger at the starting component of each subjob till you get more hands on with Talend. f you notice my job, its always staring from left to write and control goes to next area through On Subjob OK clause (which means the job will wait till the execution is complete of that full subjob before going to next Sub job).

0683p000009M0pX.png

 

 

For better readability, I have added a dummy tjava component which will control the flow. 

 

Now, another thing if younotice, you are takig NB_LINE from wrong component inyour flow. You ha earlier specified that you want to compare the count between DB and file. So you need to take the first count from DB (may be by using a select count(*) ) and store it in context variable. Next, you will have to read the NB_LINE after reading the file. 

0683p000009M0zD.png

 

 

Warm Regards,

 

Nikhil Thampi

Anonymous
Not applicable
Author

Na i need to compare values from two DB's, the difference is that I am inserting rows in one of these DB juste before my select count(*).

 

That's why i use this formula : ((Integer)globalMap.get("tDBOutput_3_NB_LINE_INSERTED")). It returns me the number of rows inserted in my DB output. This number (of inserted rows) must be equal to the number of datas that I can find in an other DB (the one i query with my select count(*)).

 

Also, I have added an empty tjava component like you suggested in order to control the flow but that's not working. The flow is still running upside down...

 

0683p000009M0qp.png

 

There is a real issue with this flow ... my println are done after the execution of the tDie component (and that's why the test returns me an inequality) ... I don't understand how this could happen because I am using that "OnSubjobOk" link before the tDie component... 

 

 

 

Anonymous
Not applicable
Author

Hi,

 

     Your first if condition check is giving the output as false (as shown in your screenshot) and second if condition is giving as true (which is going to tDie). So it seems the your if condition has some problem. Why don't you print the values using Java String.out function and see whether the values are matching or not?

 

      You are just around the corner for the final solution. I would suggest you to do some debugging around that variables and you will be able to resolve the solution. In this way, you will never forget the concepts also.

 

     If the answer has helped to answer your query, could you lease mark the topic as resolved? Kudos are also welcome 🙂

 

Warm Regards,

 

Nikhil Thampi