Scenario 2: Processing rows of data with tJavaFlex - 6.3

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

This scenario describes a two-component Job that generates random data and then collects that data and does some transformation on it line by line using Java code through the tJavaFlex component.

Setting up the Job

  1. Drop tRowGenerator and tJavaFlex from the Palette onto the design workspace.

  2. Connect the components together using a Row Main link.

Configuring the input component

  1. Double-click tRowGenerator to display its Basic settings view and the [RowGenerator Editor] dialog box where you can define the component properties.

  2. Click the plus button to add four columns: number, txt, date and flag.

  3. Define the schema and set the parameters to the four columns according to the above capture.

  4. In the Functions column, select the three-dot function [...] for each of the defined columns.

  5. In the Parameters column, enter 10 different parameters for each of the defined columns. These 10 parameters corresponds to the data that will be randomly generated when executing tRowGenerator.

  6. Click OK to validate your changes and close the editor.

Configuring the tJavaFlex component

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

  2. Click Sync columns to retrieve the schema from the preceding component.

  3. In the Start code field, enter the code to be executed in the initialization phase.

    In this example, the code indicates the initialization of the tJavaFlex component by displaying the START message and defining the variable to be used afterwards in the Java code:

    System.out.println("## START\n#");
    int i = 0;

  4. In the Main code field, enter the code to be applied on each line of data.

    In this example, we want to show the number of each line starting from 0 and then the number and the random text transformed to upper case and finally the random date set in the editor of tRowGenerator. Then, we create a condition to show if the status is true or false and we increment the number of the line:

    System.out.print(" row" + i + ":");
    System.out.print("# number:" + row1.number);
    System.out.print (" | txt:" + row1.txt.toUpperCase());
    System.out.print(" | date:" + row1.date);
    if(row1.flag) System.out.println(" | flag: true");
    else  System.out.println(" | flag: false");
    
    i++;

    Warning

    In the Main code field, "row1" corresponds 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 message:

    System.out.println("#\n## END");

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 randomly generated data that was modified by the java command set through tJavaFlex.