Configuring the components - 7.3

Java custom code

Version
7.3
Language
English
Product
Talend Big Data
Talend Big Data Platform
Talend Cloud
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Data Governance > Third-party systems > Custom code components (Integration) > Java custom code components
Data Quality and Preparation > Third-party systems > Custom code components (Integration) > Java custom code components
Design and Development > Third-party systems > Custom code components (Integration) > Java custom code components
Last publication date
2024-02-21

Procedure

  1. Double-click the tFileInputDelimited component to display its Basic settings view in the Component tab.
  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, and define the first line of the file as the header.
    In this example, the input file has the following content:
    City;Population;LandArea;PopDensity
    Beijing;10233000;1418;7620
    Moscow;10452000;1081;9644
    Seoul;10422000;605;17215
    Tokyo;8731000;617;14151
    New York;8310000;789;10452
  3. Click the [...] button next to Edit schema to open the Schema dialog box, and define the data structure of the input file. Then, click OK to validate the schema setting and close the dialog box.
  4. Double-click the tJavaRow component to display its Basic settings view in the Component tab.
  5. Click Sync columns to make sure that the schema is correctly retrieved from the preceding component.
  6. In the Code field, enter the code to be applied on each line of data based on the defined schema columns.
    In this example, we want to transform the city names to upper case, group digits of numbers larger than 1000 using the thousands separator for ease of reading, and print the data on the console:
    System.out.print("\n" + input_row.City.toUpperCase() + ":");
    System.out.print("\n - Population: " 
    + FormatterUtils.format_Number(String.valueOf(input_row.Population), ',', '.') + " people");
    System.out.print("\n - Land area: " 
    + FormatterUtils.format_Number(String.valueOf(input_row.LandArea), ',', '.') 
    + " km2");
    System.out.print("\n - Population density: " 
    + FormatterUtils.format_Number(String.valueOf(input_row.PopDensity), ',', '.') + " people/km2\n");
    Note:

    In the Code field, input_row refers to the link that connects to tJavaRow.