Search code examples
talend

looping on Value of Column in Talend


I have a scenario. In One of my Master Job 3 Child Job will run. Now after Each Child Job On SubJobOk in toraclerow an update will run to update status in Database for that Particular Table based upon Maximum(Update_Date). In next tOracleInput I am selecting the status of the Table which ran in the First Child Job and passing to that tjavarow where I am passing that Status Value to a Context.

From tjavarow using RunIF condition I am triggering the 2nd ChildJob. Now I am using the RunIF Condition like context.status.equals("Y"). Now I want to do a negative testing where I want to loop based upon some iteration to check for some time whether Status Value changed to N to Y.

My Job Design is like this now:

ChildJob1---OnComponentOk---toracleRow(UpdateRunning to change status from N to Y)---OnComponentOk---toracleinput(selecting the status of the table related to ChildJob1)---->tjavarow(Passing the STATUS Value to context)--------RunIF(context value equals "Y")----->ChildJob2

I want to loop now whether the status is still N. It will check whether Status changed to Y or not. Zero Byte file based option can't be taken.


Solution

  • I'm not sure this is what you want; if you want to loop on a child job until a flag is set by it, you can do this :

    tLoop (while context.status.equals("N"))-- Iterate -- tRunJob (childjob) -- row -- tJavaRow (context.status = row.status)
    

    inside the tLoop, set loop type as While, and in Condition, type context.status.equals("N") (and clearing Declaration and Iteration boxes).

    Your child job passes the status to the calling job using a tBufferOutput which has a single column status. Then the tRunJob needs to have the same schema as the tBufferOutput, and the checkbox "Propagate the child result to the output schema" checked. The status returned by the child job is then assigned to context.status. On the next iteration, tLoop either continues looping if context.status is equal to "N" or stops if it's "Y".
    To ensure you child job runs at least once, context.status needs to be set to "N" first.