Talend tJavaRow

Talend tJavaRow component accepts input rows and generates the output rows. We can use this tJavaRow to write a custom Java code to perform any transformation. In general, people coming from Java backgrounds use this tJavaRow to accomplish anything or everything. 

In this example, we use this Talend tJavaRow component to write Java code that performs string conversations and mathematical operations.

Talend tJavaRow example

First, we used tDBConnection, tDBCommit, tDBInput to establish an SQL connection and select the Customer table.

Configure the connection and source table

Next, drag the Talend tJavaRow component from the palette to the job design. From the tooltip, tJavaRow allows us to manually enter the main Java code part of a component.

Add Talend tJavaRow to the Workflow

The Component tab has the Java code section with some code samples and schema options. Please check the schema using the Edit Schema button.

Clicking the Generate Code button will generate the following code. It assigns the output row (tJavaRow output) values to input_row (values coming from tDBInput). It means the following code will read all the records and assign them to tJavaRow.

Click the Generate Code button

Let me assign a tLogRow to Talend tJavaRow to check whether the records are coming. From the below screenshot, you can see the result.

Run the Talend tJavaRow Job

Let me add a few more columns to the tJavaRow output by clicking the Edit Schema button in the Component tab.

Add Few More columns in the Edit Schema window

As you can see from the below Talend tJavaRow code:

  • FullName: Concatenation of First Name and Last Name and a space between them.
  • Upper_Edu = We used the Talend toUpperCase() function to convert the Education column to Uppercase.
  • Lower_Occ = We used the Talend toLowerCase() function to convert the Occupation column to Lowercase.
  • NewIncome: Here, we were adding a 15% bonus to existing income.
Write the Java Code

And the Java code that we used the above is

output_row.EmpID = input_row.EmpID;
output_row.FirstName = input_row.FirstName;
output_row.LastName = input_row.LastName;
output_row.Education = input_row.Education;
output_row.Occupation = input_row.Occupation;
output_row.YearlyIncome = input_row.YearlyIncome;
output_row.Sales = input_row.Sales;
output_row.HireDate = input_row.HireDate;
output_row.FullName = input_row.FirstName + " " +input_row.LastName;
output_row.Upper_Edu = input_row.Education.toUpperCase();
output_row.Lower_Occ = input_row.Occupation.toLowerCase();
output_row.NewIncome = input_row.YearlyIncome + input_row.YearlyIncome / 15;

Please run the tJavaRow job to see the below result.

Run the Talend tJavaRow. tool Job

Let me replace the tLogRow with tDBOutput to save the result in a Talend_JavaRow.

Configure tDBOutput output table

Let us run the Talend tJavaRow job.

Run Talend tJavaRow job to save in sql table

Please open Management Studio to check the result in the SQL table.

Destination Table