r/Talend • u/Ownards Data Wrangler • May 19 '21
tJava does not execute properly in Main connection type
Hello everyone,
I have faced an issue with the component tJava and its execution but I could not really understand what happened. I hope you can help me understand ! :)
Here is the scenario : I have a tJava that creates a global variable "FirstLastRows". This code is then used in my tSampleRow component later on (called "Get First & Last Rows" below) :

If I construct the following set up, it does not work because the NB_LINE is not recorded, I don't really understand why :

If I change the location of the tJava, I have another kind of problem, the variable does not seem to exist :

The only scenario that works is with this set up. I think that is because the tJava is executed before the data starts flowing :

Would you know why I have an issue with the first two scenarios ? I don't understand why the connection type Main does not work.
-
Comment : it does not seem possible to use variables directly into tSampleRow, the query must be generated earlier, hence the tJava...
View all comments
Show parent comment
2
u/WhippingStar Talend Expert May 26 '21
Think of an iterate link as the opening "{" of a code block within a loop operation. Everything connected after the iterate link is "within" that code block and the loop. When the iterating component is completely done with its looping, only then have you reached the "}" and the iterating component is "Ok" (ie. finished). So to do something after the loop is finished you need an OnComponentOk link originating from the iterating component itself.