Max of the Data

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Max of the Data

Post by asitagrawal »

Hi,

In my Job,
corresponding to values from a Seq File, my Database will return say 10 rows.
Now i want to do gp by on these 10 rows.
Similarly for the next row of data coming from the File, another set of some rows will be returned and a Gp by will be done on them too.
I dont have to combine the Gp By results of both the sets of data.


How do I do it?

Thx.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Your issue is a little... hard to follow. How about some examples? Post some samples of input data and what you want to come out the other end.
-craig

"You can never have too many knives" -- Logan Nine Fingers
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Post by asitagrawal »

chulett wrote:Your issue is a little... hard to follow. How about some examples? Post some samples of input data and what you want to come out the other end.
Please chk my post, topic = 'Group By in DB2 Stage and Ref from hash File ', and see if that explains sth.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not really... which is why you got the 'use the Aggregator' response. Most people aren't going to burn alot of brain cells trying to puzzle out what the heck you mean, so throw us a bone here. Post examples.
-craig

"You can never have too many knives" -- Logan Nine Fingers
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Post by asitagrawal »

This is an example, hope it expalins sth:

Code: Select all

A SQL Record (reference link)		
F1#	F2#	F3#	F4#
1	2	3	4
1	2	4	5
2	3	4	3
2	3	5	8
2	3	6	9
3	4	1	2
4	1	2	3

Hash File (Source or Stream Link)			
f1	f2		
1	2		
2	3		
3	4		
4	1		
			
for f1=1 and f2=3, from 'A' I get
F1#	F2#	F3#	F4#
1	2	3	4
1	2	4	5

So I want the below output for each row coming from the hash file.

Output			
F1#	F2#	Max(F3#)Max(F4#)
1	2	4	5
2	3	6	9
3	4	1	2
4	1	2	3

Max values are found from the set of values returned by matching F1# with f1 and F2# with f2	.	
Last edited by asitagrawal on Fri Nov 03, 2006 11:30 am, edited 1 time in total.
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post by DeepakCorning »

Can not you do this before putting the data in the hashed file ==

Select F1#,F2#,MAX(F3#),MAX(F4#) from A group by F1#,F2#

That way your hashed file will have only one record corresponding to the F! and F2 fields and then you can do the lookup with out any comlex logic.

Hope this makes sense.
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Post by asitagrawal »

DeepakCorning wrote:Can not you do this before putting the data in the hashed file ==

Select F1#,F2#,MAX(F3#),MAX(F4#) from A group by F1#,F2#

That way your hashed file will have only one record corresponding to the F! and F2 fields and then you can do the lookup with out any comlex logic.

Hope this makes sense.
No No,

the 'A' SQL record is my lookup and the hash file is the source. Now for each row of Hash File, the 'A' SQL record will return a set of rows (F1#,F2#,F3#,F4#). Now I have to find the Max(F3#) and Max(F4#) from this set of data.
DeepakCorning
Premium Member
Premium Member
Posts: 503
Joined: Wed Jun 29, 2005 8:14 am

Post by DeepakCorning »

Can you explain in a small simple mapping view kind of thing the above requirement like --

Hashed File
|
|
A ---- Trans ------


Because I am now confused , and will like to know why we can not perform the MAX thing.
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Post by asitagrawal »

DeepakCorning wrote:Can you explain in a small simple mapping view kind of thing the above requirement like --

Hashed File
|
|
A ---- Trans ------


Because I am now confused , and will like to know why we can not perform the MAX thing.
We cannot do the MAX thing coz of 'Row By Row' processing becosue of which the DB Stage will not return the SET of data which shud be returned for the mathcing keys.[/img]
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

Perform a join with the keys (F1,F2). Pass the output to an Aggregator. Group by (F1,F2). For the derivation of F3 and F4, use 'Last' (Assuming they are sorted...if not, use MAX().

gateleys
asitagrawal
Premium Member
Premium Member
Posts: 273
Joined: Wed Oct 18, 2006 12:20 pm
Location: Porto

Post by asitagrawal »

gateleys wrote:Perform a join with the keys (F1,F2). Pass the output to an Aggregator. Group by (F1,F2). For the derivation of F3 and F4, use 'Last' (Assuming they are sorted...if not, use MAX().

gateleys
Hi,

Please chk the example in the the post above.

Also explain me, that since the result of the query from the DB2 Stage will be a SET of rows, will all the rows of that SET be processed, coz I feel that only one row can move on a link at one time and not a SET if data.

Also explain me where to find abt the 'Last' in Aggregator Actions. What does this action do?

Thx
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

asitagrawal wrote:Also explain me where to find abt the 'Last' in Aggregator Actions. What does this action do?
:? It does exactly what it sounds like it would do. It is part of a related series of actions that don't technically do any 'aggregation':

First
Last
Max
Min


Each one works within each 'group' you are aggregating on. For each aggregation group, it takes the corresponding field value from the rows that made up that group - the first value, the last value, etc - and passes that value out.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply