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 a Java code that performs string conversations and mathematical operations.

Talend tJavaRow example

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

Source and Destination 1

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

Talend tJavaRow 2

Within the Component tab it has the java code section with some code samples and schema options. Please check the schema using the Edit Schema button.

tDBInput 3

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.

Generate Code 4

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

Talend tJavaRow 5

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 6

As you can see from the below code:

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

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.

Talend tJavaRow 8

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

Add Output Table Name 9

Let us run the Talend tJavaRow job.

Talend tJavaRow 10

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

SQL Destination Table 11