One Input to multiple output function

Seven Stars

One Input to multiple output function

i have a data set as below (only dummy):

Country; Person; Email

India; abc; 123@gmail.com

India; def; 456@gmail.com

India; xyz; 356@gmail.com

USA; hjg; 876@gmail.com

USA; jki; 986@gmail.com

Canada; oiu; 354@gmail.com

Canada; uyr; 876@gmailcom

 

the above data set is a result set of my logic. i need to send a mail as below:

1. All persons listed in India should get one mail and that mail body/atachment should not have other country details.

2. All persons listed in USA should get one mail and that mail body/atachment should not have other country details.

Similar for Canada also.

 

In my actual result set, there will be around 50 countries. I do not prefer writing 50 outputs using tMap. Rather would like to implement some looping kind of stuff. Not sure how to build that. Can someone please help?

Can someone please help on how to being this.


Accepted Solutions
Highlighted
Community Manager

Re: One Input to multiple output function

OK. I get it now. The way I would do this is to create a flow like below....

 

Initial data ------>tSortRow------> tMap------->tAggregateRow------>tSendMail

 

First you need to sort your initial data by country. Once it is sorted by country, you can use the tMap to build your TO list. Now this is the complicated bit. You need to use the tMap variables' functionality to hold data between rows to do this. BUT you also need to clear the data when the country changes. So given the data set you have shown, when the country is India, your TO variable will grow like this.....

 

abc1@abc.com

abc1@abc.com, abc2@abc.com

abc1@abc.com, abc2@abc.com, abc3@abc.com

 

.....at this point the country changes and the TO variable will be reset. I do something similar in this mini tutorial (https://community.talend.com/t5/How-Tos-and-Best-Practices/Compare-row-value-against-a-value-from-th...). Pay attention to logic for recognising when the group key value has changed and how I reset the variables.

 

After the tMap, you will end up with multiple rows per country....but you want one. This is why we have the taggregateRow. Group by country and set the column functions to Last for all rows. This will return 1 row per country, with your complete TO string returned (as it will be complete for the last row processed for each country).

 

This is a good lesson to get to grips with some cool tMap functionality.

View solution in original post


All Replies
Highlighted
Community Manager

Re: One Input to multiple output function

Can you keep that body/attachment (info pointing to or actual attachment) in a database? If so, you can simply join to your dataset and out put a different body/attachment using a single tMap output.

Tags (1)
Highlighted
Seven Stars

Re: One Input to multiple output function

Yes, i thought of that option. But we are not allowed to store the data in any other DB.

My problem is, how will i send separate mails from the data set?

If person 123 belongs to India, he should receive the data w.r.t India and not USA/Canada.

FYI, the source for this is from SQL DB & MongoDB.

Tags (1)
Highlighted
Community Manager

Re: One Input to multiple output function

OK, I understand that you cannot keep the data in your database, but you will have to keep it somewhere. Anywhere you keep that data, it can be acquired by Talend. You just need to be able to point to it. Do you have the body in a file somewhere (for each country?), you just need a filepath to that file(s). There is absolutely no need to have an output in your tMap for every country. 

Highlighted
Seven Stars

Re: One Input to multiple output function

Hello! Thanks for your reply.
Sorry I am not clear on ur point. Actually, I have one output file which has 10 columns. This file will be sent (as attachment) in a mail to a specific list of users.
I have to send another mail to users given in the above output file. But these users are grouped based on Country. So that, users belonging to one country will receive details only about them and it will not include details of others users from different countries. This is my actual requirement.

Can you please explain your solution on this?
Sorry, i am new to Talend. So i find it difficult to select the components.

My thoughts:
I created a file with list of users and their countries. Then I join this output with the above output file. Then using a tFlowToIterate, i tried to run a loop. Please let me know if this approach is correct or any better solutions. I am also stuck in the output of tFlowToIterate.
Tags (1)
Highlighted
Community Manager

Re: One Input to multiple output function

Sorry, I thought this was more complicated. This appears relatively straight forward. You are storing your data in rows. Data within rows do not get mixed or aggregated unless you actively work to do that. Therefore you can connect to a tSendMail and your data will be sent out as you wish. One email per row in your above table

Highlighted
Seven Stars

Re: One Input to multiple output function

output.JPG

Above is my final data set. What i have to do is given in the 4th column.

The Customer should get mail about the country to which they belong. 

Highlighted
Community Manager

Re: One Input to multiple output function

OK. I get it now. The way I would do this is to create a flow like below....

 

Initial data ------>tSortRow------> tMap------->tAggregateRow------>tSendMail

 

First you need to sort your initial data by country. Once it is sorted by country, you can use the tMap to build your TO list. Now this is the complicated bit. You need to use the tMap variables' functionality to hold data between rows to do this. BUT you also need to clear the data when the country changes. So given the data set you have shown, when the country is India, your TO variable will grow like this.....

 

abc1@abc.com

abc1@abc.com, abc2@abc.com

abc1@abc.com, abc2@abc.com, abc3@abc.com

 

.....at this point the country changes and the TO variable will be reset. I do something similar in this mini tutorial (https://community.talend.com/t5/How-Tos-and-Best-Practices/Compare-row-value-against-a-value-from-th...). Pay attention to logic for recognising when the group key value has changed and how I reset the variables.

 

After the tMap, you will end up with multiple rows per country....but you want one. This is why we have the taggregateRow. Group by country and set the column functions to Last for all rows. This will return 1 row per country, with your complete TO string returned (as it will be complete for the last row processed for each country).

 

This is a good lesson to get to grips with some cool tMap functionality.

View solution in original post

Highlighted
Seven Stars

Re: One Input to multiple output function

Thanks for the reply. This is really interesting for a person like me, who is an entry level.

 

BTW, i tried the same logic (as below) given in the link to your post

Var.prev_county!=null && Var.prev_county.compareToIgnoreCase(row11.Country)==0
? row11.Email :row11.Email

Here the Email is not getting lined up for same country as below:

abc1@abc.com, abc2@abc.com, abc3@abc.com

instead it is displaying the result (Email) one by one. I think this is because of using ur logic (in that link) as it is.

Can you please tell me where i went wrong?

 

Highlighted
Seven Stars

Re: One Input to multiple output function

Thanks for your reply!

From the link you have given i tried below logic

Var.prev_county!=null && Var.prev_county.compareToIgnoreCase(row11.CountyFA)==0
? row11.ContactEmail : row11.ContactEmail

And this dose not return data as "abc1@abc.com, abc2@abc.com, abc3@abc.com" Instead it prints the Email one by one.

Can you please correct my logic and let me know where i went wrong?

 

FYI. From the data set i shared (as attachment) before, a total of only 4 mails will be triggered.

One each for India, USA, Canada & Japan. 

 

Highlighted
Community Manager

Re: One Input to multiple output function

Did this solve your issue?

Highlighted
Seven Stars

Re: One Input to multiple output function

i replied to you yesterday with a query. Not sure, why was it not displayed here. Anyways, just modified a bit of ur valiable (from the link provided) and it worked. But still, there was an issue. I wanted to send mail one by one - Customer from India will get one mail, Customer from USA will get one mail, Customer from Canada will get one mail. And these mails will not have details of other countries. For that I was stuck in iterate process. And at last it woked out Smiley Happy
Thanks for ur support and patience Smiley Happy

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog