Scenario 3: Using tJavaFlex to display file content based on a dynamic schema - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
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
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

This scenario describes a three-component Job that uses Java code through a tJavaFlex component to display the content of a file being transferred from the source to the target. As all the components in this Job support the dynamic schema feature, we can leverage this feature to save the time of configuring each column of the schema.

Setting up the Job

  1. Drop tFileInputDelimited, tJavaFlex, and tFileOutputDelimited from the Palette onto the design workspace.

  2. Connect the components in a series using Row > Main links.

  3. Label the components according to their roles in the Job.

Configuring the input and output components

  1. Double-click the tFileInputDelimited component, which is labeled Source, to display its Basic settings view where you can define the component properties.

    Warning

    The dynamic schema feature is only supported in Built-In mode and requires the input file to have a header row.

  2. In the File name/Stream field, type in the path to the input file in double quotation marks, or browse to the path by clicking the [...] button.

  3. In the Header field, type in 1 to use the first line of the file as the header.

  4. Click the [...] button next to Edit schema to open the [Schema] dialog box.

  5. Click the [+] button to add a column, give a name to the column, dyna in this example, and select Dynamic from the Type list. This dynamic column will retrieve the three columns, FirstName, LastName and Address, of the input file.

  6. Click OK to validate the setting and close the dialog box.

  7. Double-click the tFileOutputDelimited component, which is labeled Target, to display its Basic settings view where you can define the component properties.

  8. Define the output file path in the File Name field.

  9. Select the Include Header check box to include the header in the output file. Leave all the other settings are they are.

Configuring the tJavaFlex component

  1. Double-click tJavaFlex to display its Basic settings view and define the components properties.

  2. Click Sync columns to make sure that the schema is correctly retrieved from the preceding component.

  3. In the Start code field, enter the following code:

    System.out.println("Content of file being transferred:\n");
  4. In the Main code field, enter the code to be applied on each line of data.

    In this example, we want to display the content of the source file based on the defined dynamic schema column:

    System.out.println(row1.dyna);

    Warning

    In the Main code field, "row1" refers to the name of the link that connects to tJavaFlex. If you rename this link, you have to modify the code.

  5. In the End code field, enter the code that will be executed in the closing phase.

    In this example, the code indicates the end of the execution of tJavaFlex by displaying the "End of file" message:

    System.out.println("\nEnd of file");

Saving and executing the Job

  1. Save your Job by pressing Ctrl+S.

  2. Execute the Job by pressing F6 or clicking Run on the Run tab.

    The console displays the content of the input file. As the Data Auto Propagate check box is selected by default, the content of the file is intactly transferred to the output component.