Scenario: Printing out a variable content - 6.1

Talend Components Reference Guide

Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
Data Governance
Data Quality and Preparation
Design and Development
Talend Studio

The following scenario is a simple demo of the extended application of the tJava component. The Job aims at printing out the number of lines being processed using a Java command and the global variable provided in Talend Studio.

Setting up the Job

  1. Select and drop the following components from the Palette onto the design workspace: tFileInputDelimited, tFileOutputExcel, tJava.

  2. Connect the tFileInputDelimited to the tFileOutputExcel using a Row Main connection. The content from a delimited txt file will be passed on through the connection to an xls-type of file without further transformation.

  3. Then connect the tFileInputDelimited component to the tJava component using a Trigger > On Subjob Ok link. This link sets a sequence ordering tJava to be executed at the end of the main process.

Configuring the input component

  1. Set the Basic settings of the tFileInputDelimited component.

  2. Define the path to the input file in the File name field.

    The input file used in this example is a simple text file made of two columns: Names and their respective Emails.

  3. Click the Edit Schema button, and set the two-column schema. Then click OK to close the dialog box.

  4. When prompted, click OK to accept the propagation, so that the tFileOutputExcel component gets automatically set with the input schema.

Configuring the output component

Set the output file to receive the input content without changes. If the file does not exist already, it will get created.

In this example, the Sheet name is Email and the Include Header box is selected.

Configuring the tJava component

  1. Then select the tJava component to set the Java command to execute.

  2. In the Code area, type in the following command:

    String var = "Nb of line processed: ";
    var = var + globalMap.get("tFileInputDelimited_1_NB_LINE");

    In this use case, we use the NB_Line variable. To access the global variable list, press Ctrl + Space bar on your keyboard and select the relevant global parameter.

Job execution

Save your Job and press F6 to execute it.

The content gets passed on to the Excel file defined and the Number of lines processed are displayed on the Run console.