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,380 points
781 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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:

image

Open the Map Editor and map the data as shown:

image

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("res.id");

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

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;

row2.id = currentId;

row2.name = 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!!

image

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

Related Questions In Talend

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,380 points
517 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Looping through all the schemas in Talend

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

answered Apr 10, 2018 in Talend by code.reaper12
• 3,450 points
52 views
0 votes
1 answer

Parsing JSON in Talend

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

answered Apr 2, 2018 in Talend by code.reaper12
• 3,450 points
358 views
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 16, 2018 in Talend by code.reaper12
• 3,450 points
372 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.