What component can be used to duplicate every row of an excel file using Talend?

769 views Asked by At

If I have an excel file with rows like this:

val1 | val2 | val3 | val4
val5 | val6 | val7 | val8

then I need the result to be this:

val1 | val2 | val3 | val4
val1 | val2 | val3 | val4
val5 | val6 | val7 | val8
val5 | val6 | val7 | val8

Is this possible with Talend?

EDIT: Notice the order of the rows. I need them to maintain order.

2

There are 2 answers

9
RealHowTo On BEST ANSWER

Send 2 identical inputs to a tUnite to duplicate the row. Then send the rows to a tSort to sort them.

enter image description here

The 2 tFlowInput are identical, replace them with what you have.

enter image description here

Sync Columns on the tJoin. Set the columns to sort on the tSort

enter image description here

Output :

.---------+----------+----------+----------.
|                tLogRow_1                 |
|=--------+----------+----------+---------=|
|newColumn|newColumn1|newColumn2|newColumn3|
|=--------+----------+----------+---------=|
|val1     |val2      |val3      |val3      |
|val1     |val2      |val3      |val3      |
|val5     |val6      |val7      |val8      |
|val5     |val6      |val7      |val8      |
'---------+----------+----------+----------'
4
Carassus On

For a pure duplication, the easiest would be to use a tHashInput to store the values coming from your Excel file.

Then you can read from a linked tHashOutput twice and join the flows with a tUnite.


If you need to keep the order, you can add a tJavaRow or a tMap before the tHashInput to add a column "order" valued with a sequence. Then you can add a tSortRow after the tUnite and order with the new column. Finally, you delete the extra column with a tFilterColumn (or any other component).

enter image description here

Result :

enter image description here

Code for the order :

Numeric.sequence("s1",1,1);

Note : you might have to add the components tHashOutput and tHashInput to your palette as they are not included by default.