One Star

Multiple output rows on custom component

Hello
I'm creating a custom component.
this component have 2 outputs rows and I want data to flow through one row at a time (not both the 2 rows).
Can you tell me how I can achieve it ?
Thanks,
Regards
tChangeTest.rar.rar 
11 REPLIES
Moderator

Re: Multiple output rows on custom component

Hi,
We are working on your another topic:https://www.talendforge.org/forum/viewtopic.php?id=44396 then come back to you asap!
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Fifteen Stars

Re: Multiple output rows on custom component

If you are working on a component with two outputs, I am assuming that you have got to the stage where your component is outputting the same thing via the 2 outputs. If that is the case, then why do you not just implement some sort of procedure to switch the output you are sending data to for every row? I am assuming that you want to achieve the following....
Input Data
1
2
3
4
Output1
1
3
Output2
2
4
Rilhia Solutions
One Star

Re: Multiple output rows on custom component

If you are working on a component with two outputs, I am assuming that you have got to the stage where your component is outputting the same thing via the 2 outputs. If that is the case, then why do you not just implement some sort of procedure to switch the output you are sending data to for every row? I am assuming that you want to achieve the following....
Input Data
1
2
3
4
Output1
1
3
Output2
2
4

Thanks for you answer but I already know how to do this.

My real problem is that I don't want to get : http://www.noelshack.com/2015-29-1437142034-capture.png
Output1
1rows
Output2
1rows
I want control the rows data flow like this:
Output1
1rows
Output2
0rows
OR
Output1
0rows
Output2
1rows
One Star

Re: Multiple output rows on custom component

Fifteen Stars

Re: Multiple output rows on custom component

How do you want to decide which output is getting the data? Is there some sort of logic you are basing this on, is this a setting based on a datarow or is this decided at design time?
Also, your screenshot is misleading I think. Are you assuming that because you are seeing "1 rows" on both outputs that they are being output together? Is the data from output1 and output2 the same or is it different but appears to be happening at the same time?
You say that you know how to shift the datarow from one output to the other. If that is the case, what is the problem you are struggling with? If you know how to do this, then it is very easy to implement any logic you want to decide when the output will switch, which output it will switch to, etc.
Rilhia Solutions
One Star

Re: Multiple output rows on custom component

Thanks for your reply.
See below the logic to switch on which output to write :
<% 
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode) codeGenArgument.getArgument();
NodeConnectionsHelper connsHelper=new NodeConnectionsHelper(node, true);
String cid = node.getUniqueName();
IConnection inputConn = connsHelper.getInputConn();
if(inputConn == null)
{
return "";//not generate any code if no input connection.
}
IConnection connResponse = connsHelper.getOutputConnResponse();
IConnection connFault = connsHelper.getOutputConnFault();
%>
if (<%=inputConn.getName()%>.InputColumn == "toto")
{
<%=connResponse.getName()%>.Result = <%=inputConn.getName()%>.InputColumn;
java.util.List<String> responseList_<%=cid%> = null;
responseList_<%=cid%> = new java.util.ArrayList<String>();
responseList_<%=cid%>.add(<%=inputConn.getName()%>.InputColumn);
responseList_<%=cid%>.add(<%=inputConn.getName()%>.InputColumn);
responseList_<%=cid%>.add(<%=inputConn.getName()%>.InputColumn);
<%=connResponse.getName()%>.OutputColumn = responseList_<%=cid%>;
}
else if (<%=inputConn.getName()%>.InputColumn != "toto") {
<%=connFault.getName()%>.error_id = <%=inputConn.getName()%>.InputColumn;
<%=connFault.getName()%>.error_message = <%=inputConn.getName()%>.InputColumn;
}

As you can see above, the 2 outputs are connResponse and connFault. You can also see that we write on one output at the time.
On my screenshot, data are written only on connResponse. But nevertheless, empty data flows through connFault.
This is our issue : we don't want any row flow through connFault when switch to connResponse (even if it's an empty row).
Also we don't want any row flow through connResponse when switch to connFault.
Hope it's clear.
Thanks in advance
Fifteen Stars

Re: Multiple output rows on custom component

Sorry, I have looked again and think I see your problem. You are getting a row from both outputs every time, but only one of those outputs is actually holding data. So like this....
Output1  Output2
1           null
null        2
3           null
null        4
But what you want is this....
Output1  
1
3
Output2
2
4
I'm not sure this is easy at all. Take a look at components like tMap which handle this sort of functionality. They have the concept of tMapIn and tMapOut sub components. If you do find out, I would be interested to see how you do it. Unfortunately the Talend Component Designer is the least documented piece of functionality and a lot of what I have learnt is through trial and error.
Rilhia Solutions
Fifteen Stars

Re: Multiple output rows on custom component

I believe this is caused because the output objects (IConnections) that are instantiated in the Java Main file are always triggered to return a response even if it is null (ie you have not assigned it a value). Therefore I believe it requires the sub component design model where you can make use of the sub component output you require for each row. As I said before, this is guess work from playing around with the code.
Rilhia Solutions
One Star

Re: Multiple output rows on custom component

This is exactly the issue rhall_2.0. Can you give me more details about your proposed solution please ? Thanks
Fifteen Stars

Re: Multiple output rows on custom component

I'm afraid I have not spent much time (if any) looking into this. If I were to start looking into it, I would look at the code for the tMap or tFilterRow components. Both of those demonstrate the sort of functionality that you want. I *think* it might have something to do with the sub component model I mentioned. The tMap has tMapIn and tMapOut components that appear to be used by the tMap. I suspect this has something to do with it.
Sorry I can't be of more help, but I would have to spend several hours looking into this and I do not have the time at the moment. It has raised an interest and I will look into it, but I am on a project at the moment and just don't have the time. Let us know if you find out how this is done.
Good luck
Rilhia Solutions
One Star

Re: Multiple output rows on custom component

I want to get the same output row management functionality as tESBConsumer.
But trying to reproduce by using the same code doesn't work for me.
tChangeTest.rar_20150721-1844.rar