talendtmapexpressionbuilder

How to map different columns of ONE table into ONE column of ONE table using Talend


I have one table with different columns. The columns belong to an Id, x and y. I would like to map those columns into One unique ID, X and Y using talend: I have a connection to my DB from MySQL to Talend. Im adding my table as a "MySQLInput".
The table looks like:

idN| XN  |YN   | idT |XT   | YT
1  | 2.5 | 4.5 | 2   | 6.9 | 2.7
2  | 6.9 | 2.7 | 7   | 9.9 | 2.1
5  | 4.6 | 6.6 | 9   | 1.3 | 5.5
7  | 3.2 | 7.8 | 6   | 3.2 | 3.1

I want this table as a result after mapping with talend:

idU | XU | YU
1   | 2.5 | 4.5
2   | 6.9 | 2.7
5   | 4.6 | 6.6
6   | 3.2 | 3.1
7   | 3.2 | 7.8
7   | 9.9 | 2.1
9   | 1.3 | 5.5

I try to do that:

enter image description here

But the result is not what i expect:

IDU | XU | YU
1 | 2.5  | 4.5
2 | 6.9  | 2.7
5 | 4.6  | 6.6
7 | 3.2  | 7.8

I have tried also doing this:

enter image description here

using that expression but code gives me an error.

I also tried to create my own routine and using it in the Expression builder but still not working.

Does anyone have hint about how to conduct this mapping, or what component to use. The thing is that i don't have only 2 times the same columns but three or more in the same table and I need to map them all at one final and unique column per each one of the similar variables.

thanks for taking your time to reading this , and double thanks to answer it :)


Solution

  • Here's a simple solution using tSplitRow:

    enter image description here

    You need to split each incoming row into 2 rows: one with idN, XN, YN and the 2nd one having the columns idT, XT, YT. tSplitRow has the columns id, X, Y.
    Then use a tUniqRow to filter out duplicates, like this :

    enter image description here

    And the output :

    .--+---+---.
    |tLogRow_5 |
    |=-+---+--=|
    |id|X  |Y  |
    |=-+---+--=|
    |1 |2.5|4.5|
    |2 |6.9|2.7|
    |7 |9.9|2.1|
    |5 |4.6|6.6|
    |9 |1.3|5.5|
    |7 |3.2|7.8|
    |6 |3.2|3.1|
    '--+---+---'