Search code examples
concatenationrowtalend

How concatenate 2 column that contains multiple rows of data


I work with Talend 6.3. I want to concatenate 2 columns in tmap. But in specifics rows, there are multiple data and i want match them the first with the first of the row in the other column.

Example :

  • 2 columns : Name and Surname

  • In Name, I have : Kevin,Zoe,Alan

  • In Surname, I have : Monta,Rey,Zom

I want an other row that concatenates Kevin with Monta, Zoe with Rey, Alan with Zom.

How do that with talend? Because in tmap if I concatenate classic, I will have only one success concatenation.

I don't know if I explained that correctly but tell me if someone need more information.

Thanks in advance

The job :

enter image description here

Add other data -> Login is the ID

enter image description here

enter image description here


Solution

  • So we have a flow with an ID and 2 columns (Name and Surname), each contain n elements. n can vary from row to row.

    The goal is to have a final flow with the concatenation of all Name + Surname with the ID intact.

    It's not a super Talend-y way, but you can use tFlowToIterate to access each row individually and do the pairing of Name + Surname.

    After, we access the resulting list and use tNormalize to split it :

    screenshot job

    Code for the tJava component :

    List<String> nameList = Arrays.asList(((String)globalMap.get("row5.Name")).split("\\s*,\\s*"));
    List<String> surnameList = Arrays.asList(((String)globalMap.get("row5.Surname")).split("\\s*,\\s*"));
    
    for (int index = 0; index < nameList.size(); index++) {
        ((ArrayList<String>) context.concat).add(((Integer)globalMap.get("row5.id")) + ";" + nameList.get(index) + ";" + surnameList.get(index));
    }
    

    Code for the tFixedFlowInput "Use context (list)" :

    StringHandling.EREPLACE(StringHandling.EREPLACE(context.concat.toString(),"\\[",""),"\\]","")
    

    Result :
    enter image description here