Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to Perform Cumulative in Talend

Hi,

 

I am new to Talend and trying to explore on talend with more use cases. I have a below requirement.

Could any one please suggest on this. I have tried with tmemorize and tmap components and unable to reach the requirement. 

 

Also is it possible to compare previous record with current record in talend as we do in Informatica.

 

I/P:

ID;DEPTNO;SAL

111;10;200

112;20;300

113;10;400

114;30;500

115;20;500

116;20;200

 

O/P:

ID;DEPTNO;SAL

111;10;200;200

113;10;400;600

112;20;300;300

115;20;500;800

116;20;200;1000

114;30;500;500

 

Thanks in Advance..

 

Regards,

venkat.

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Hi,

Here is a solution:

0683p000009LwaI.png

tSortRow to order input by detpno

tJavaRow to compute cumulative values using global variable to store intermediate result:

//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(row32.deptno)) != null){
	output_row.cumul = (Integer)globalMap.get(Integer.toString(row32.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);
}

The result:

Starting job test at 11:06 10/09/2017.

[statistics] connecting to socket on port 3455
[statistics] connected
111|10|200|200
113|10|400|600
112|20|300|300
115|20|500|800
116|20|200|1000
114|30|500|500
[statistics] disconnected
Job test ended at 11:06 10/09/2017. [exit code=0]

Hope this helps.

View solution in original post

2 Replies
TRF
Champion II
Champion II

Hi,

Here is a solution:

0683p000009LwaI.png

tSortRow to order input by detpno

tJavaRow to compute cumulative values using global variable to store intermediate result:

//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(row32.deptno)) != null){
	output_row.cumul = (Integer)globalMap.get(Integer.toString(row32.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);
}

The result:

Starting job test at 11:06 10/09/2017.

[statistics] connecting to socket on port 3455
[statistics] connected
111|10|200|200
113|10|400|600
112|20|300|300
115|20|500|800
116|20|200|1000
114|30|500|500
[statistics] disconnected
Job test ended at 11:06 10/09/2017. [exit code=0]

Hope this helps.

Anonymous
Not applicable
Author

Thanks a lot. Very clearly explained.