How to get the smallest number

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
tomengers
Participant
Posts: 167
Joined: Tue Nov 19, 2002 12:20 pm
Location: Key West

How to get the smallest number

Post by tomengers »

Hi All ...

I've been trying to fit this requirement into a hash file without success. I know I can solve this with a temporary table, but I'd rather do a hash: I will create a series of rows out of my Transform. These rows will contain a column named smallest_nbr which is a value achieved by subtracting two dates. I need to identify the row with the smallest value (and yes, I will have to deal with potential duplicates). Is sorting this file the only way to deal with this issue?

thanks ...

... tom
kiran_kom
Participant
Posts: 29
Joined: Mon Jan 12, 2004 10:51 pm

Re: How to get the smallest number

Post by kiran_kom »

Use the aggregator stage. Pretty easy to use.
tomengers wrote:Hi All ...

I've been trying to fit this requirement into a hash file without success. I know I can solve this with a temporary table, but I'd rather do a hash: I will create a series of rows out of my Transform. These rows will contain a column named smallest_nbr which is a value achieved by subtracting two dates. I need to identify the row with the smallest value (and yes, I will have to deal with potential duplicates). Is sorting this file the only way to deal with this issue?

thanks ...

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

Post by chulett »

You could also do this with a hash if that's the way you want to go. :wink:

Create one with a fixed key so it only has one record - like a "1" - and a data field to hold your number. Setup your job to do the lookup from and also write to this hash file. On each row, compute the number, do the lookup and compare the two. If your new number is smaller than your old number, write it to the hash. When you are done... smallest number.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Provided you disable write cache, and set the read cache to "disabled, lock for updates", Craig's solution will work.

The hashed file stage is not suited to what you are trying to do. Because of the way a hashed file works, calculating the actual (physical) location of the record based on the key value (zero I/O cost to find the key) rather than using an index or a table scan, the only kind of lookup you can do on a hashed file is the equivalent of WHERE key = ?

However, since a hashed file is how a UV table is implemented, you can use a UV stage to refer to the hashed file, and use regular SQL to extract the minimum value. SELECT MIN(columnname) FROM hashedfilename;
This will probably not be as fast as using an Aggregator stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
tomengers
Participant
Posts: 167
Joined: Tue Nov 19, 2002 12:20 pm
Location: Key West

Post by tomengers »

Kiran - Craig - Ray ...

Many thanks for your input. Damn, now I've got 3 choices ... :D

... tom
Post Reply