How to generate multiple rows from a single row in Talend

0 votes

I have a file with data in the following format:

id  | name  | dateFrom   | dateTo

101 | Allen | 12-04-2018 | 17-04-2018

Can someone help me in splitting up this single row of into multiple rows where the number of output rows will depend on the difference between the dates? For example, the output must look like:

New_id | id  | name |   dateFrom   |  dateTo

1        101  Allen    12-04-2018    13-04-2018

2        101  Allen    13-04-2018    14-04-2018

3        101  Allen    14-04-2018    15-04-2018

4        101  Allen    15-04-2018    16-04-2018

5        101  Allen    16-04-2018    17-04-2018


Apr 18, 2018 in Talend by misc.edu04
• 1,440 points

1 answer to this question.

0 votes

I think using tJavaFlex, tMap and tFlowToIterate components you can easily split the data. You can start off by arranging the components as shown below:


Open the Map Editor and map the data as shown:


In the Map Editor output table add a new row called “iterations” of “long” type to hold the difference between the dates.

tFlowToIterate components need no configurations to be done. It will by default pass on the values to the tJavaFlex.

Add the below code to the tJavaFlex component:

Start Code:

 // start part of your Java code

int currentId = (Integer)globalMap.get("");

String currentName = (String)globalMap.get("");

Long iterations = (Long)globalMap.get("res.iterations");

Date dateFrom = (java.util.Date)globalMap.get("res.dateFrom");

Date dateTo = (java.util.Date)globalMap.get("res.dateTo");

for(int i=0; i<((Long)globalMap.get("res.iterations")); i++) { 

Main Code:

row2.new_id = i+1; = currentId; = currentName;

row2.dateFrom = TalendDate.addDate(dateFrom, i, "dd");

row2.dateTo = TalendDate.addDate(dateFrom, i+1, "dd");

End Code:


Like the tFlowToIterate component tLogRow also do not need any configurations to be done. You can just go ahead and execute the job which will give you the below output. Hope this was what you were looking for. Cheers!!


answered Apr 18, 2018 by code.reaper12
• 3,500 points

Related Questions In Talend

0 votes
1 answer

In Talend, how to specify multiple conditions as expression

@Palaniswamy, have a look at this discussion ...READ MORE

answered Aug 5, 2019 in Talend by Vardhan
• 13,190 points
0 votes
1 answer

How to loading flat file from configuration in Talend?

Hey, @There, Regarding your query you need to ...READ MORE

answered Jun 4, 2020 in Talend by Gitika
• 65,950 points
0 votes
0 answers

How can I use talend to extract data from Oracle and import the data into a MSSQL database?

We currently have around 100 Oracle tables ...READ MORE

Nov 4, 2020 in Talend by umesh
• 150 points
0 votes
1 answer

Using tHiveRow to execute multiple Hive queries in Talend

In order to execute multiple queries, you ...READ MORE

answered Apr 14, 2018 in Talend by misc.edu04
• 1,440 points
0 votes
1 answer

Looping through all the schemas in Talend

It is really simple to make tOracleInput ...READ MORE

answered Apr 11, 2018 in Talend by code.reaper12
• 3,500 points
0 votes
1 answer

Parsing JSON in Talend

While working with JSON files, one thing ...READ MORE

answered Apr 3, 2018 in Talend by code.reaper12
• 3,500 points
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

How to load a set of files into database using Talend

Using tFileList component,  you can read all the files present ...READ MORE

answered Apr 17, 2018 in Talend by code.reaper12
• 3,500 points