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,450 points
7,816 views

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:

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. 

Get your Talend certification today to become certified professional.

Thanks.

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,150 points
7,221 views
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,770 points
2,183 views
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
2,560 views
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,450 points
3,838 views
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
1,898 views
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
4,094 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 17, 2018 in Talend by code.reaper12
• 3,500 points
6,168 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP