Talend Datatype Conversion

In this chapter, we explore the Talend tConvertType element to perform datatype conversions. In real-time, we won’t get the data in the desired data type so we have to use Talend datatype conversation field to convert them as per the business requirements. For example, we might get the date and time in string format or sales in string format. In such a situation, we use this Talend datatype conversation transformation.

To demonstrate this Talend Datatype conversation filed, we are using the below shown text file.

Talend Datatype Conversion 1

Talend datatype conversion Example

As we all know, we need tFileInputDelimited field to work with text file. So, drag the same and select the text file from file system Here, we are using the file directly, but you have the option to use the Repository file.

Talend Datatype Conversion 2

Here, you can see the Schema of all the columns.

Talend Datatype Conversion 3

Next, drag and drop the Talend tConvertType to the job design area. As you can see from the tooltip, tConvertType converts one Talend Java type to another.

Talend Datatype Conversion 4

Please connect the main row to Talend tConvertType.

Talend Datatype Conversion 5

Next, click on the Edit Schema button to change the data types of the required columns. If you don’t see the source column then click on the Sync columns button.

Talend Datatype Conversion 6

Let me change the EmpID to integer, yearly Income and Sales to Double, and Hire Date to Date data type. Don’t forgot to assign appropriate length, precision, and date format.

Talend Datatype Conversion 7

Please checkmark the other two options are Auto Cast, and Set empty values to Null before converting (important).

Talend tConvertType 8

Let us create an empty table in SQL Server. Or you can select the existing table.

Talend tConvertType 9

Next, we used tDBOutput to connect to SQL Server. Here, we are using the repository connection.

Talend tConvertType 10

Next, we selected the newly created table, i.e., Talend_ConvertType.

Talend tConvertType 11

Click on the Edit Schema to check the input and output columns.

Talend tConvertType 12

Let us run the Talend datatype conversion job.

Talend tConvertType 13

Within the Management Studio, you can see the data.

Talend tConvertType 14

This time, we unchecked the Auto Cast option, and did the manual casting of the columns.

Talend tConvertType 15

Again run the Talend datatype conversion job.

Talend tConvertType 16