Search code examples
talend

How to create two excel lines from one line


I'm a beginner on Talend Studio.

My problem

I don't know how to create two lines from one line.

I have an excel file with these columns: LastName, FirstName, Course1, Course2, Results.

My objective

My objective is to create an excel output file but with a column named Course.

So my header will be LastName, FirstName, Course.

My input file contains 40 lines. So my output file must contains 80 lines.

My actual structure

I'm using tFileExcelInput, tMap and tFileExcelOutput.

actual structure

Here, OutConc_1_ is Course1. And AnalDon_1_ is Course2.

Finally, Note is the global column (Course).

Error

However, when I do these joins, I get this error:

Compilation error : AnalDon_1_ cannot be resolved or is not a field.

(If I join firstly AnalDon_1_ and then OutConc_1_, the error is: OutConc_1_ cannot be resolved or is not a field.)

Example

Input file

LastName,FirstName,Course1,Course2,Result
John,Test,10,15,12.5
Mike,Dupond,6,9,7.5

Result excepted:

LastName,FirstName,Course
John,Test,10
John,Test,15
Mike,Dupond,6
Mike,Dupond,9

Thank's for help.


Solution

  • So you want each row to generate two rows in the target. One row where Course is Course1, and a 2nd row where Course is Course2. You can do this :

    enter image description here

    Use tSplitRow to generate 2 rows from each input row (notice that only Note column is different between the 2 rows). If you need to add another column to the Note output column, just add a row to tSplitRow and map it with the values you want.