Talend tMap Type Conversion

This article shows how to use the Talend tMap to perform type conversion or change data types. We can use this Talend tMap as an alternative to tConvertType to change the column’s data type based on the requirement. In real-time, we mostly get the data in string format so, we have to change them to an integer, double, date, etc. 

To demonstrate the Talend tMap Type Conversion, we use the Customer_text text file that we used in the tConvertType example. So, let me use the tFileInputDelimited and choose the text file from the file system.

Talend tMap Type Conversion 1

Click on the Edit Schema button to add all the columns with data types. Or, if you have the existing metadata, please use the same. Anyways, you can see all the columns are of string type.

Talend tMap Type Conversion 2

Drag and drop the Talend tMap, and connect the tFileInputDelimited Main row to tMap.

Talend tMap Type Conversion 3

Double-click on the tMap opens the below window. Please click on the + button to add new output. Let me add all the columns from row1 to Type_Conversion_Out (the name we gave to this output).

Talend tMap Type Conversion 4

Our scenario is that we have a predefined table to store these records. And the table has EmpID of integer type, Income of Double, Sales as float type, and HireDate as the Date format. So, to meet the same, we changed the data type of the above-specified columns to the same.

Talend tMap Type Conversion 5

Let me run this Talend tMap Type Conversion job and see what will happen.

Talend tMap Type Conversion 6

As you can see from the above tMap image, it is throwing an error (type mismatch).

Talend tMap Type Conversion Steps

Please click on the browse button beside the EmpID will open the expression builder to write an expression. Please use this expression builder or perform typecasting or Conversion.

Talend tMap Type Conversion 7

For this column, we have to change the string type to integer. So, we are using the parseInt method. If you find it challenging to write a function, press the control + space to see the possibilities. Or, under Categories, you can find all the built-in functions.

Talend tMap Type Conversion 8

Click the Ok button to close the window.

Talend tMap Type Conversion 9

Similarly, we use parseDouble to convert string to double, parseFloat to convert string to float, and parseDate to convert a string value to date. Remember, for parseDate, please match the column pattern to the date format.

Talend tMap Type Conversion 10

For the time saving, we used the tLogRow to display the result. From the below image, you can see the Talend tMap Type Conversion result.

Talend tMap Type Conversion 11