[resolved] Duplicate Rows based on a column value

One Star

[resolved] Duplicate Rows based on a column value

Hi Guys,
I have a tricky job to do. Basically I want to change the number of tuples I have in a source component based on a number located into a filed. I explain:
Entry File
No Name Number
1 Dupont 4
Output File
No Name
1 Dupont
1 Dupont
1 Dupont
1 Dupont
Is there any simple trick I can use?
Another quick trick I require, I have a filed that looks like : ;;;;;;;1;;;;1;;;;1
And I would like to be able to addition those numbers... any java killer method could help?
Many thanks folks!

Accepted Solutions
Community Manager

Re: [resolved] Duplicate Rows based on a column value

Hello
Is there any simple trick I can use?

Yes, it is easy to finish in TOS. Here is a java senario:
in.csv:

1;Dupont;4
2;Shong;3

Result:
Starting job forum6760 at 10:53 27/05/2009.
1|Dupont
1|Dupont
1|Dupont
1|Dupont
2|Shong
2|Shong
2|Shong
Job forum6760 ended at 10:53 27/05/2009.

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

All Replies
One Star

Re: [resolved] Duplicate Rows based on a column value

Another quick trick I require, I have a filed that looks like : ;;;;;;;1;;;;1;;;;1
And I would like to be able to addition those numbers... any java killer method could help?

String[] tab = ";;;;;;;1;;;;1;;;;1".split(";");
int result = 0;
for(String s : tab) {
if(s.matches("+")) {
result += Integer.parseInt(s);
}
}
Community Manager

Re: [resolved] Duplicate Rows based on a column value

Hello
Is there any simple trick I can use?

Yes, it is easy to finish in TOS. Here is a java senario:
in.csv:

1;Dupont;4
2;Shong;3

Result:
Starting job forum6760 at 10:53 27/05/2009.
1|Dupont
1|Dupont
1|Dupont
1|Dupont
2|Shong
2|Shong
2|Shong
Job forum6760 ended at 10:53 27/05/2009.

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Duplicate Rows based on a column value

shong beat me to it, but I've used the tFor in my solution. Good use of the "Number of rows"in the tFixedFlowInput shong!
I think this proves that there are many ways to skin the cat when you've got such a great tool to work with.
.. I want to change the number of tuples I have in a source component based on a number located into a filed

Load the fields into context variables first.
Iterate using a tLoop, up to the count in the context variable.
Use a tFixedFlowInput to insert the context variables into the data stream.
I've used a tLogRow, but if you want the flow out to a file you'll need to make sure you append.
Cheers,
c0utta
Highlighted
One Star

Re: [resolved] Duplicate Rows based on a column value

Guys, you all saved me!!! I 'll implement that today...
Remy (who loves this community...)
One Star

Re: [resolved] Duplicate Rows based on a column value

Hello
Is there any simple trick I can use?

Yes, it is easy to finish in TOS. Here is a java senario:
in.csv:

1;Dupont;4
2;Shong;3

Result:
Starting job forum6760 at 10:53 27/05/2009.
1|Dupont
1|Dupont
1|Dupont
1|Dupont
2|Shong
2|Shong
2|Shong
Job forum6760 ended at 10:53 27/05/2009.

Best regards

       shong

how you do that ?
regards,
G.
Community Manager

Re: [resolved] Duplicate Rows based on a column value

how you do that ?


The job design is as below:
tFileInputDelimited--main(row1)-->tFlowToIterate--iterate-->tFixedFlowInput--main--tLogrow
on tFixedFlowInput, set the number of Row field with the current Number value, for example:
(Integer)globaoMap.get("row1.Number")
About tFlowToIterate component, refer to the user manual:
https://help.talend.com/reader/JuYAu6ZYt6JnyC2yfuo83w/~aaaL9zPp0xMBTIBqNXMmw
Best regards
Shong

----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Duplicate Rows based on a column value

Thank you very much Smiley Happy
You save my day!
Regards,
G.

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch