Talend run-if none triggered - talend

I have several run-if conditions.I could have a catch all that ANDs and NOTs the several run-if conditions to run when none of them trigger.
Is there an alternative method to have a path chosen when none of the run-if conditions returned true?

There is no "else" link in Talend to do that automatically.
One solution would be to rewrite a condition which is the negative of all the others one combined.
Otherwise, if you can check the condition on your input flow (e.g : "XX"!=row1.myData), you can direct your flow on a tMap , and have multiple outputs on your tMap : each output could be filtered with one condition, and you can have a resulting output with "catch output reject" option. Only doable if the condition is on a data on the flow.

Related

Throw error on invalid lookup in Talend job that populates an output table

I have a tMap component in a Talend job. The objective is to get a row from an input table, perform a column lookup in another input table, and write an output table populating one of the columns with the retrieved value (see screenshot below).
If the lookup is unsuccessful, I generate a row in an "invalid rows" table. This works fine however is not the solution I'm looking for.
Instead, I want to stop the entire process and throw an error on the first unsuccessful lookup. Is this possible in Talend? The error that is thrown should contain the value that failed the lookup.
UPDATE
A tfileoutputdelimited componenent would do the staff .
So ,the flow would be as such tMap ->invalid_row->tfileoutputdelimited -> tdie
Note : that you have to go to advanced settings in the tfileoutputdelimited component aand tick split output into multiple files option and put 1 rather then 1000
For more flexibility , simply do two tmap order than one tMap

ANDALSO options, stop evaluating when one fails

I have a SQL select statement that reads items. There are conditions for which items to display, but when one condition fails, I don't need to check the other.
For example:
where item like 'M%'
and item_class='B'
and fGetOnHand(item)>0
If either of the first 2 fail, i do NOT want to do the last one (a call to a user defined function).
From what I have read on this site, SQL Server's AND and OR operators do not follow short circuiting behavior. This means that the call to the UDF could happen first, or maybe not at all, should one of the other conditions happen first and fail.
We might be able to try rewriting your logic using a CASE expression, where the execution order is fixed:
WHERE
CASE WHEN item NOT LIKE 'M%' OR item_class <> 'B'
THEN 0
WHEN fGetOnHand(item) <= 0
THEN 0
ELSE 1 END = 1
The above logic forces the check on item and item_class to happen first. Should either fail, then the first branch of the CASE expression evaluates to 0, and the condition fails. Only if both these two checks pass would the UDF be evaluated.
This is very verbose, but if the UDF call is a serious penalty, then perhaps phrasing your WHERE clause as above would be worth the trade off of verbose code for better performance.

Talend do not execute component at 0 rows

I've filtred some data with a tFilterRow, it is working fine, but at O rows the flow with 0 rows continue executing components :
I have 2 queries at the end of filter and reject flows and both are executed !
I don't want my query to be executed at 0 rows
any help ?
Thanks in advance.
Just for reference. tJava is a special component that always gets executed. It shouldn't be used with an incoming flow.
Here's a demonstration :
tJava and tJavaFlex have the same code. It gets printed in tJava but not in tJavaFlex.
You could use the Run If trigger for your components. And put the trigger condition as per the criteria when you connect your one component to another stating that -
execute the component only if the number of rows is greater than 0
Sample job layout -
You can also use global variable available in tFilterow like 1>((Integer)globalMap.get("tFilterRow_1_NB_LINE_OK")) and 2> ((Integer)globalMap.get("tFilterRow_1_NB_LINE_REJECT")). Create two link one with filter name and other with reject
In if link just use this variables with condition like
for Filer link: - ((Integer)globalMap.get("tFilterRow_1_NB_LINE_OK")) > 0
for Reject link : - ((Integer)globalMap.get("tFilterRow_1_NB_LINE_REJECT")) > 0

talend - put a logic before tOutput

I have a talend job that have the following components:
- 1 database input component that fetched data from the database
- 1 output component that writes the fetched data into flat file.
Now, I have a scenario wherein, from two fields on the fetched data, only one should be put on in the output based on some if else logic.
Can anyone assist me in this matter? Is it using tMap?
Your if/else logic could be put in the tMap; as a ternary operator in the output of your tMap.
condition?resultifOK:resultifKO
For example, you want to insert in your file the value of ColumnA if it is "MY CONDITION", otherwise you insert value of ColumnB :
You'll have, directly in the output row of tMap:
"MY CONDITION".equals(row1.ColumnA)?row1.ColumnA:row1.ColumnB
You can't directly use a if/else in tMap. If you have several conditions , consider using a Routine instead of multiple ternary operators.

How to conditionally execute something based on previous processed number of rows?

I want to execute some subjob if the previously processed number of rows are greater than N. To do this, i'm using the following configuration:
tFixedFlowInput have some rows.
tAggregateRow uses the count function and outputs one row with the number.
tSetGlobalVar then stores this value into a global var that I can check in the Run If connector (In this case, (Integer)globalMap.get("tSetGlobalVar_1") > 3 ).
tMsgBox then shows if the condition is true.
What I would like is to do the same, but in a more elegant way, using the minimum components required. I would like to connect tAggregateRow with the Run If connector directly (or even tFixedFlow) with tMsgBox, but I haven't found a way to refer to the number of rows previously processed without using the output row2.count variable.
How could I do something like this?
What should I put in the If condition to refer to the tAggregateRow operation result without connecting it to another meaningless component like exposed at the beginning?
for any talend component look under outline tab under the left side workspace pane at the bottom. this lists down the properties available via global variables for that component. Some properties like count of records inserted by output components are only available once the component is executed completely (After).
for your case you can try directly using ((Integer)globalMap.get("tFixedFlowInput_1_NB_LINE")) which gives number of lines (after) given by tFixedFlowInput.