Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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.
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.
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.
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.
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
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.
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.
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?
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.