Fill a simple 1-N relation

One Star

Fill a simple 1-N relation

Hello everybody.

I need to fill mainly, two tables: users and files. So, each user has several documents and a file has only one owner (user).

First, I understand I need to generate a sample users. I'm using tRowGenerator with (id, username, firstname, lastname) schema.
Otherwise, I'm using a tFileList component in order to "generate" a list of files on a (filename field) schema. I'd like to merge this data (users and files).

I'm quite figuring out I need a tMap component, however, I don't know how to relate users and filename...
I'll appreciate a lot any help.
Thanks for all.

Moderator

Re: Fill a simple 1-N relation

Hi,
Have you already checked component reference TalendHelpCenter:tMap with scenarios?

I'm quite figuring out I need a tMap component, however, I don't know how to relate users and filename...


Would you mind setting an example with input and expected output result so that we can design a demo job for you?



Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Fill a simple 1-N relation

1. I'd like to fill a simple users collections (id, username, firstname, lastname)
2. For each created user, I'd like to assign several filenames assigned to each user.
Ten Stars

Re: Fill a simple 1-N relation

OK, this looks like an experiment with using Talend since you are using a tRowGenerator to generate users, etc. Therefore, the answer is simple. You need to assign a "key". This should be a number. Each user generated should have a number assigned to it. So if you have 10 users, the numbers could be 1 to 10. Then when you are getting the files from the file list, generate a random number (between 1 to 10) and assign it to the file. This will mean that a user can have several files, but a file can only have 1 user. Then you simply create an inner join in the tMap using the user number
One Star

Re: Fill a simple 1-N relation

Ok, thanks rhall. I've gone ahead.
However, I'm indexing 1000 rows (users), but I'm inserting 1000 files yet. I'd like to insert every file generated.
As you can see, I'm generating 1000 users and 20000 files. However I'm indexing 1000 users but only 1000 files.
Ten Stars

Re: Fill a simple 1-N relation

If you have added a screenshot, I can't see it I'm afraid.
One Star

Re: Fill a simple 1-N relation

I've attached it again...

Ten Stars

Re: Fill a simple 1-N relation

OK, I think I can see what you are saying. Can you take a screenshot of your tMap component? Also, how are you assigning a user number to the files? Have you assigned a random user number to the files?
One Star

Re: Fill a simple 1-N relation

Yes, I've assigned a random number between 0-1000 to user_id on tIterateFlow component (row3 input on tMap).

Ten Stars

Re: Fill a simple 1-N relation

I see. You need to change the files input (row3) to be the "Main" input and the users input (row1) to be the "Lookup". The "Main" input drives the process. So every row received will be processed. The users input is simply a lookup here.

I should point out that this is not the only way of achieving this. You can leave it as it is and click on the spanner symbol on the row3 input. If you set the "Match Model" to "All Matches" and the "Join Model" to "Inner Join", it should do this as well.

My first suggestion is based on the fact that this process looks like it is driven by the files and not the users. The dataset that is driving the process should usually be the "Main" input.

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch 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