0% found this document useful (0 votes)
13 views13 pages

Talend Tutorials & Scenarios Prepared by Venkat Rathnam Tekuri

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

Talend Tutorials & Scenarios Prepared by Venkat Rathnam Tekuri

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Talend Tutorials & Scenarios Prepared by Venkat Rathnam Tekuri

Cumulative Sum( Running total):


Source:
ID,NAME,SAL
10,VENKAT,1000
11,RATHNAM,2000
13,TEKURI,3000
14,ROHIT,6000
15,SACHIN,8000

Target:
Starting job TVR_CUMULATIVE_SUM_JOB at 19:50 27/02/2021.
[statistics] connecting to socket on port 3590
[statistics] connected
.--+-------+------.
| tLogRow_1 |
|=-+-------+-----=|
|ID|NAME |SAL |
|=-+-------+-----=|
|10|VENKAT |1000.0|
|11|RATHNAM|2000.0|
|13|TEKURI |3000.0|
|14|ROHIT |6000.0|
|15|SACHIN |8000.0|
'--+-------+------'

.--+-------+------+-------------.
| tLogRow_2 |
|=-+-------+------+------------=|
|ID|NAME |SAL |CUMULATIVESUM|
|=-+-------+------+------------=|
|10|VENKAT |1000.0|1000.0 |
|11|RATHNAM|2000.0|3000.0 |
|13|TEKURI |3000.0|6000.0 |
|14|ROHIT |6000.0|12000.0 |
|15|SACHIN |8000.0|20000.0 |
'--+-------+------+-------------'

[statistics] disconnected

Job TVR_CUMULATIVE_SUM_JOB ended at 19:50 27/02/2021. [Exit code = 0]

Procedure:

 Drop tFileInput Delimited metadata, tLogRow,tJavaFlex and tLogRow from the Palette into the
designer workspace.
 Connect the tFileInput Delimited to the by using a Row > Main link. Then, connect the
tLogRow to tJavaFlex then tLogRow, using a Row > Main link.
 Double click the tFileInput Delimited Define the properties as per the below.

 Double click the tLogRow component and define the Table (Print Values in cells of a table).
 Double click the tJavaFlex component and go to edit schema and define as per the below .

 Then go to StartCode, Main Code and End Code Define as per the below.
// start part of your Java code
float fsal=0;

float fsal=0;

// here is the main part of the component,


// a piece of code executed in the row
// loop
fsal +=row2.SAL;
//System.out.println(fsal);
row3.CUMULATIVESUM=fsal;
// end of the component, outside/closing the loop

 Double click the tLogRow component and define the Table (Print Values in cells of a table).
 Executing the Job or Save your Job and press F6 to execute it.
 You will get the two desired output.

Cumulative Sum Deptno wise:

Source:
ID,DEPTNO,SAL
101,10,1000
112,30,3000
133,30,2000
144,20,4000
154,10,6000
155,10,5000
144,20,7000
144,20,9000
133,30,8000

Target:
Procedure:

 Drop tFileInput Delimited metadata, tSortRow,tJavaRow and tLogRow from the Palette into
the designer workspace.
 Connect the tFileInput Delimited to the tSortRow, using a Row > Main link. Then connect the
Other components using a Row > Main link.
 Double click the tFileInput Delimited Define the properties as per the below.
 Double click the tSortRow component define the Deptno column in asc order.

 Double click the tJavaRow Component define the code as per the below.

//Code generated according to input schema and output schema


output_row.ID = input_row.ID;
output_row.DEPTNO = input_row.DEPTNO;
output_row.SAL = input_row.SAL;
if((Integer)globalMap.get(Integer.toString(input_row.DEPTNO)) != null){
output_row.cumul = (Integer)globalMap.get(Integer.toString(input_row.DEPTNO)) + input_row.SAL;
globalMap.put(Integer.toString(input_row.DEPTNO), output_row.cumul);
}
else{
output_row.cumul = input_row.SAL;
globalMap.put(Integer.toString(input_row.DEPTNO), input_row.SAL);
}

 Double click the tLogRow define table format and run the job you will get desired output.
Cumulative Sum DEPTNO wise AND Cumulative sum:

Source:

SalesPerson SalesYe TotalSal


Id ar es
101 2015 100
102 2015 200
103 2015 300
104 2015 400
105 2016 50
106 2016 100
107 2016 150
108 2016 200
109 2017 1000
110 2017 2000
111 2017 3000
112 2017 4000
113 2018 1050
114 2018 1100
115 2018 1150

Target:
Procedure:

 Drop tFileInput Excel metadata, tLogRow1,tJavaRow and tLogRow2 from the Palette into the
designer workspace.
 Connect the tFileInput Excel Other components using a Row > Main link.
 Double click the tFileInput Excel Define the properties as per the below.

 Double click the tJavaFlex define the code as per the below.
// start part of your Java code
float fsal=0;
float fysal=0;
int iyear=0;

// here is the main part of the component,


// a piece of code executed in the row
// loop
if (row2.SalesYear!=iyear)
{
fysal=0;
iyear=row2.SalesYear;
}

// end of the component, outside/closing the loop

 Double click the target tLogRow define the table and save the job and run the job.

You might also like