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.
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.
Drag and drop the Talend tMap, and connect the tFileInputDelimited Main row to tMap.
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).
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.
Let me run this Talend tMap Type Conversion job and see what will happen.
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.
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.
Click the Ok button to close the window.
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.
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.