Scenario 2: Extracting the contents of a dynamic column via tJavaRow - 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

In this scenario, a dynamic column is created via tWriteDynamicFields and its contents are then extracted by the customized code in tJavaRow.

Linking the components

  1. Drop tFixedFlowInput, tWriteDynamicFields, tLogRow and tJavaRow onto the workspace.

  2. Link tFixedFlowInput to tWriteDynamicFields using the Row > Main connection.

  3. Link tWriteDynamicFields to tLogRow using the Row > Main connection.

  4. Link tLogRow to tJavaRow using the Row > Main connection.

Configuring the components

  1. Double-click tFixedFlowInput to open its Basic settings view.

  2. Select Use Inline Content (delimited file) in the Mode area.

  3. In the Content field, enter the data to pass to tWriteDynamicFields, for example:

    1;Andy;Doc
    2;Anderson;Dev
  4. Click the Edit schema button to open the schema editor.

  5. Click the [+] button to add three columns, namely id, name, and dept, of the Integer and String types respectively.

  6. Click OK to validate the setup and close the editor.

  7. Double-click tWriteDynamicFields to open its Basic settings view.

  8. Click the Edit schema button to open the schema editor.

  9. Click the [+] button in the right panel to add two columns, namely id and dynamic, of the Integer and Dynamic types respectively.

    The column id contains the value of the column id from tFixedFlowInput and the column dynamic contains the values of the columns name and dept from tFixedFlowInput.

  10. Click OK to validate the setup and close the editor.

  11. Double-click tLogRow to open its Basic settings view.

    Select Table (print values in cells of a table) for a better display of the results.

  12. Double-click tJavaRow to open its Basic settings view.

  13. In the Code field, enter the Java code to extract the contents of the dynamic column dynamic:

    Dynamic columns = row3.dynamic;
     
    for (int i = 0; i < columns.getColumnCount(); i++) {  
        DynamicMetadata columnMetadata = columns.getColumnMetadata(i);  
        System.out.println(columnMetadata.getName() + ": " + 
    columns.getColumnValue(i) + "; " + columnMetadata.getType());
    } 

    The dynamic column dynamic of the flow row3 is specified for retrieving the names, values and types of columns that it contains.

Executing the Job

  1. Press Ctrl+S to save the Job.

  2. Press F6 to run the Job.

    As shown above, the columns contained in the dynamic column have been correctly extracted.