Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Talend Tutorials & Scenarios Prepared by Venkat Rathnam Tekuri

tFileInputMSDelimited Component:
Talend Read Dynamic File Structure:
The data coming in text files are unpredictable. One day, we might get 5 columns, the
next day six columns, the other day columns in a completely different order, etc.
If our source file has a dynamic structure or Muti structure, we can use the Talend
tFileInputMSDelimited component to handle the same.

Source:

Canada;12;AB;ALBERTA
Canada;34;BC;BRITISH Columbia
Canada;56;ON;Ontario
Canada;78;QC;Quebec
France;Garonne(haute);89
France;Seine;98
France;Gers;90
France;Yeline;91
France;Nord;89
Germany;HE;Hessen;101
Germany;bb;BrabdBurge;102
Germany;hh;Hamburg;103
Germany;by;bayern;105
United States;California;106;ca
United States;ohio;107;oh
United States;Maryaland;99;md
United States;llions;100;IL
Target:
Starting job TVR_DYNAMIC_FILELOADING at 18:10 15/12/2020.
[statistics] connecting to socket on port 3444
[statistics] connected
.------+-------+-------+----------------.
| tLogRow_1 |
|=-----+-------+-------+---------------=|
|Column|Column1|Column2|Column3 |
|=-----+-------+-------+---------------=|
|Canada|12 |AB |ALBERTA |
|Canada|34 |BC |BRITISH Columbia|
|Canada|56 |ON |Ontario |
|Canada|78 |QC |Quebec |
'------+-------+-------+----------------'

.------+--------------+-------.
| tLogRow_2 |
|=-----+--------------+------=|
|Column|Column1 |Column2|
|=-----+--------------+------=|
|France|Garonne(haute)|89 |
|France|Seine |98 |
|France|Gers |90 |
|France|Yeline |91 |
|France|Nord |89 |
'------+--------------+-------'

.-------+-------+----------+-------.
| tLogRow_3 |
|=------+-------+----------+------=|
|Column |Column1|Column2 |Column3|
|=------+-------+----------+------=|
|Germany|HE |Hessen |101 |
|Germany|bb |BrabdBurge|102 |
|Germany|hh |Hamburg |103 |
|Germany|by |bayern |105 |
'-------+-------+----------+-------'

.-------------+----------+-------+-------.
| tLogRow_4 |
|=------------+----------+-------+------=|
|Column |Column1 |Column2|Column3|
|=------------+----------+-------+------=|
|United States|California|106 |ca |
|United States|ohio |107 |oh |
|United States|Maryaland |99 |md |
|United States|llions |100 |Il |
'-------------+----------+-------+-------'

[statistics] disconnected

Job TVR_DYNAMIC_FILELOADING ended at 18:10 15/12/2020. [Exit code = 0]


Procedure:

 Drag and Drop the tFileInputMSDelimited component and four tLogRow


Components.
 Connect them together by using Row > Main link.
 Double Click the tFileInputMSDelimited component Please click on the Browse button
and select the Dynamic Source text file from the file system.
 Next, change the Field Separator as per your need, and click the Preview button to see the
data preview.
 If there are multiple separators in the text file to separate the columns, then checkmark Use
multiple separators option and place them in the below text box.
 Fetch the codes and click on ok map the ouput links
 Once you right-click on the Talend tFileInputMSDelimited and select the Rows option, you can
see all the outputs. For the Talend Read Dynamic File Structure example, we assigned each
output to tLogRow with table preview.

 Save the job and run the job you will get the desired output as per the above.

tForeach Component:
 Talend tForeach is the same as the foreach loop that creates a loop and iterates the same. In
this chapter, we show you a simple example of the tForeach.
 Drag and drop the tForeach component to the job designer workspace.
 As you can see from the tForeach below, it has only the Values section in the Component tab
to add values for the foreach iteration.

Procedure:
 Double click the tForeach Component and define the values as per the below.
 .

 Next, we used the tJava component to display or print those foreach iteration values.
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

Source:
EMPNO,ENAME,JOB,SAL,COMM,DEPTNO,HIREDATE
101,VENKAT,SE,5000,500.00,10,23-11-2020
102,RATHNAM,SSE,6000,600.87,20,12-10-2000
104,TEKURI,JL,4000,400.76,20,20-10-2001
103,VENKI,TL,9000,900.65,30,22-11-2010
105,VENKATA,MANAGER,10000,100.87,10,24-12-2010
106,RATHNA,ASC,20000,2000.67,20,12-12-2020
108,VENKATARATHNAM,ASC,50000,5000.34,30,22-10-2019
107,TVRATHNAM,CEO,100000,1000.54,10,27-11-2020
108,TEKUR,JLg,2000,400.56,30,29-12-2020

Target:
Starting job TVR_TMAP_TYPE_CONVERSION at 21:08 15/12/2020.
[statistics] connecting to socket on port 4007
[statistics] connected
.-----+--------------+-------+--------+-------+------+----------.
| tLogRow_1 |
|=----+--------------+-------+--------+-------+------+---------=|
|EMPNO|ENAME |JOB |SAL |COMM |DEPTNO|HIREDATE |
|=----+--------------+-------+--------+-------+------+---------=|
|101 |VENKAT |SE |5000.0 |500.0 |10 |23-11-2020|
|102 |RATHNAM |SSE |6000.0 |600.87 |20 |12-10-2000|
|104 |TEKURI |JL |4000.0 |400.76 |20 |20-10-2001|
|103 |VENKI |TL |9000.0 |900.65 |30 |22-11-2010|
|105 |VENKATA |MANAGER|10000.0 |100.87 |10 |24-12-2010|
|106 |RATHNA |ASC |20000.0 |2000.67|20 |12-12-2020|
|108 |VENKATARATHNAM|ASC |50000.0 |5000.34|30 |22-10-2019|
|107 |TVRATHNAM |CEO |100000.0|1000.54|10 |27-11-2020|
|108 |TEKUR |JLg |2000.0 |400.56 |30 |29-12-2020|
'-----+--------------+-------+--------+-------+------+----------'

[statistics] disconnected

Job TVR_TMAP_TYPE_CONVERSION ended at 21:08 15/12/2020. [Exit code = 0]

Procedure:

 Drag and Drop the Source file tFileInputDelimited component,tMap and tLogRow
Components.
 Connect them together by using Row > Main link.
 Double Click the tFileInputDelimited define the properties.

 Anyways, you can see all the columns are of string type.

 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, SAL of Double, COMM 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.
 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.
 Double click the tlogrow make a table ,Save the job and run the job.

You might also like