How to use table query results in tRowGenerator

Highlighted
Five Stars

How to use table query results in tRowGenerator

Hello,

 
If I'm in the wrong board, I apologize - I'm new to Talend and the Community.
 
I have a functionality question with tRowGenerator.  I'd like to generate random values based on a query from a table.  Is this possible to do?  If so, how?
 
If I hard-code a string of values, this works:
image.png

 

I've tried variations using a context variable, thinking I can load from the table the list, denormalize it, and then load to the context variable.  Once that is done, tRowGenerator does it's thing.  But I can't get that to work:

image.png

 

I've tried changing the type from String to List, but can't seem to get it to work.

When I hard code the list, TOS generates this following Java code:

 

public String getRandomCredentials() {

String[] CredentialsTable = new String[] { "MD", "DO",
"FNP", "AGNP", "DDS" };
java.util.Random randomtRowGenerator_1 = new java.util.Random();
return CredentialsTable[randomtRowGenerator_1
.nextInt(CredentialsTable.length)];

}

 

But when I use a context variable, it doesn't "randomize it".  It just returns the values in the context variable as a single string:

 

public String getRandomCredentials() {

return context.Credentials;

}

 

Any help is appreciated!

Highlighted
Community Manager

Re: How to use table query results in tRowGenerator

Hi @Papademuchos  and welcome to the Community!

 

I'm afraid your screenshots are not available to view. I have checked the HTML and it looks like you are sharing from Google. This does not allow others to view this. Could you use the Photos button at the top of the post window and add these?

 

Regarding your question, I think you may need to use a tMap and call the methods using Java in-line IFs to do this. I may be wrong since I am missing the images, but you might want to try that.

Highlighted
Five Stars

Re: How to use table query results in tRowGenerator

Hello, hopefully these images will come through better.  The first one is showing the literal string in the Expression Value in tRowGenerator.  It accurately randomizes my five values among the generated rows:  "AGNP","DDS","DO","FNP","MD".

 

Talend1.jpg

 

The second one is my attempt to pull the values from a database table and put them into a context variable.  I can do that part just fine, but tRowGenerator doesn't see them as a list of values, but a single value.

Talend2.jpg

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

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog