tConvertType - 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

Function

tConvertType allows specific conversions at runtime from one Talend java type to another.

Purpose

Helps to automatically convert one Talend java type to another and thus avoid compiling errors.

tConvertType properties

Component family

Processing

 

Basic settings

Schema and Edit Schema

A schema is a row description. It defines the number of fields (columns) to be processed and passed on to the next component. The schema is either Built-In or stored remotely in the Repository.

Click Edit schema to make changes to the schema. If the current schema is of the Repository type, three options are available:

  • View schema: choose this option to view the schema only.

  • Change to built-in property: choose this option to change the schema to Built-in for local changes.

  • Update repository connection: choose this option to change the schema stored in the repository and decide whether to propagate the changes to all the Jobs upon completion. If you just want to propagate the changes to the current Job, you can select No upon completion and choose this schema metadata again in the [Repository Content] window.

 

 

Built-In: You create and store the schema locally for this component only. Related topic: see Talend Studio User Guide.

 

 

Repository: You have already created the schema and stored it in the Repository. You can reuse it in various projects and Job designs. Related topic: see Talend Studio User Guide.

 

Auto Cast

This check box is selected by default. It performs an automatic java type conversion.

 

Manual Cast

This mode is not visible if the Auto Cast check box is selected. It allows you to precise manually the columns where a java type conversion is needed.

 

Set empty values to Null before converting

This check box is selected to set the empty values of String or Object type to null for the input data.

 

Die on error

Note

Not available for Map/Reduce Jobs.

This check box is selected to kill the Job when an error occurs.

Advanced settings

tStatCatcher Statistics

Select this check box to gather the Job processing metadata at a Job level as well as at each component level.

Global Variables

ERROR_MESSAGE: the error message generated by the component when an error occurs. This is an After variable and it returns a string. This variable functions only if the Die on error check box is cleared, if the component has this check box.

NB_LINE: the number of rows read by an input component or transferred to an output component. This is an After variable and it returns an integer.

A Flow variable functions during the execution of a component while an After variable functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl + Space to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio User Guide.

Usage

This component cannot be used as a start component as it requires an input flow to operate.

Limitation

n/a

Scenario: Converting java types

This Java scenario describes a four-component Job where the tConvertType component is used to convert Java types in three columns, and a tMap is used to adapt the schema and have as an output the first of the three columns and the sum of the two others after conversion.

Note

In this scenario, the input schemas for the input delimited file are stored in the repository, you can simply drag and drop the relevant file node from Repository - Metadata - File delimited onto the design workspace to automatically retrieve the tFileInputDelimited component's setting. For more information, see Talend Studio User Guide.

Dropping the components

  1. Drop the following components from the Palette onto the design workspace: tConvertType, tMap, and tLogRow.

  2. In the Repository tree view, expand Metadata and from File delimited drag the relevant node, JavaTypes in this scenario, to the design workspace.

    The [Components] dialog box displays.

  3. From the component list, select tFileInputDelimited and click Ok.

    A tFileInputComponent called Java types displays in the design workspace.

  4. Connect the components using Row > Main links.

Configuring the components

  1. Double-click tFileInputDelimited to enter its Basic settings view.

  2. Set Property Type to Repository since the file details are stored in the repository. The fields to follow are pre-defined using the fetched data.

    The input file used in this scenario is called input. It is a text file that holds string, integer, and float java types.

    Fill in all other fields as needed. For more information, see tFileInputDelimited. In this scenario, the header and the footer are not set and there is no limit for the number of processed rows.

  3. Click Edit schema to describe the data structure of this input file. In this scenario, the schema is made of three columns, StringtoInteger, IntegerField, and FloatToInteger.

  4. Click Ok to close the dialog box.

  5. Double-click tConvertType to enter its Basic settings view.

  6. Set Schema Type to Built in, and click Sync columns to automatically retrieve the columns from the tFileInputDelimited component.

  7. Click Edit schema to describe manually the data structure of this processing component.

    In this scenario, we want to convert a string type data into an integer type and a float type data into an integer type.

    Click OK to close the [Schema of tConvertType] dialog box.

  8. Double-click tMap to open the Map editor.

    The Map editor displays the input metadata of the tFileInputDelimited component

  9. In the Schema editor panel of the Map editor, click the plus button of the output table to add two rows and name them to StringToInteger and Sum.

  10. In the Map editor, drag the StringToInteger row from the input table to the StringToInteger row in the output table.

  11. In the Map editor, drag each of the IntegerField and the FloatToInteger rows from the input table to the Sum row in the output table and click OK to close the Map editor.

  12. In the design workspace, select tLogRow and click the Component tab to define its basic settings. For more information, see tLogRow.

Executing the Job

  1. Press Ctrl+S to save the Job.

  2. Press F6 to execute it.

    The string type data is converted into an integer type and displayed in the StringToInteger column on the console. The float type data is converted into an integer and added to the IntegerField value to give the addition result in the Sum column on the console.