Using tjavarow component to transform a data flow

Six Stars

Using tjavarow component to transform a data flow

Hello guys! 

I've been doing talend for a month now and have finished almost all exercises provided by talendforge and also most exercises provided in the internet. But one advanced exercise really had me stuck for quite awhile, it was in exercise 10 where what i have to do is I have to configure a tjavaflex so that it will generate two NSS(honestly, until now I really dont know what's this): "2700392000000", and "1760991000000". You also have to create a month, year and department columns within the tjavaflex. After creating it somehow, you put another tjavarow where you will have to instantiate the variables corresponding to the output data. Im really sorry if this sounds so confusing, but the exercise really is(or how its written), but somehow I really want to know how to solve this exercise. Anyways, I'll be attaching the screenshot below and any help would be always appreciated 

Thanks and God Bless


Ten Stars

Re: Using tjavarow component to transform a data flow

With a tJavaFlex component, you have 3 code sections; start code, main code and end code. If you want to generate rows, you can use these sections in the following way to generate data rows. The below example is a simple example of how to generate 2 two rows with random data....
Start Code
for(int i = 0; i<2; i++){

The above will create a loop that will loop twice. Check For Loops out in regard to Java to see how this works. 

Main Code
row1.col1 = routines.TalendString.getAsciiRandomString(10);
row1.col2 = routines.TalendString.getAsciiRandomString(10);

The above will populate two columns (col1 and col2) with random Strings for each iteration of the loop. "row1" is the name of the row connected to the tJavaFlex.
End Code

The above simply ends the loop created in the Start Code.
Six Stars

Re: Using tjavarow component to transform a data flow

I know how to create a simple table using tjavaflex, its just that this one particular exercise really got me stuck...the table that it wanted me to output will look like this:

              Input        |                    Ouput                    |
NSS                       |     Month     | Year  | Department |
--------------------------------------------------------------- |
[font=Verdana, Helvetica, Arial, sans-serif]2700392000000      |       03         | [/font][font=Verdana, Helvetica, Arial, sans-serif]1970 |      92         |[/font]
[font=Verdana, Helvetica, Arial, sans-serif]1760991000000      |       09         | [/font][font=Verdana, Helvetica, Arial, sans-serif]1976 |      91         |[/font]

[font=Verdana, Helvetica, Arial, sans-serif]I only got to the part in creating the 2 NSS numbers and what really confuses me is how to use that to have the output like the one showed above where there is a "Month", "Year" & "department" the exercise, it uses a tjavarow to do that...but it didnt really specified on how to do it...

Anyways, I really appreciate any help from you guys Smiley Happy

One Star

Re: Using tjavarow component to transform a data flow

Hi novastorm33
I am not sure if you are looking for the code something like below-

one you have generated NSS in a variable called nss. you can use below code to generate rest of the fields-
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]month=nss.substring(3, 5);[/font][/color]
[color=#5b5b5d][font=Verdana, Helvetica, Arial, sans-serif]dept=nss.substring(5,7);[/font][/color]
year="19"+nss.substring(1, 3);



Talend named a Leader.

Get your copy


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 1

Learn how to do cool things with Context Variables


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


Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables