Key column in Hashed File

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
ravij
Premium Member
Premium Member
Posts: 170
Joined: Mon Oct 10, 2005 7:04 am
Location: India

Key column in Hashed File

Post by ravij »

Hi,

I am loading the data from db2 to Hashed file. I have a key column in Hashed file. suppose if the key column is having 5 same values which value out of 5 will store in the hashed file either first or second.....fifth?

thanks in advance.
Ravi
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

The last one.

--Balaji S.R
ravij
Premium Member
Premium Member
Posts: 170
Joined: Mon Oct 10, 2005 7:04 am
Location: India

Key column in Hashed File

Post by ravij »

thanks Balaji,

But if i want to take the first record what should I do?

thanks in advance.
Ravi
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

Think whether is it necessary to use Hashed file?

How is the value stored in DB2. Is there any primary key for the table you are loading. How does table identify unique rows? Make the primary key of DB2 table as key of hashed file.

--Balaji S.R
ravij
Premium Member
Premium Member
Posts: 170
Joined: Mon Oct 10, 2005 7:04 am
Location: India

Key column in Hashed File

Post by ravij »

Hi Balaji,

I will give a simple scenario here. I am loading two columns into Hashed file from DB2. one is Key col. suppose the data is like

key col1 col2
10 x
10 y
10 z
when I load the data into hashed file i will get only the last record i.e 10, z but i want the value x to be loaded into my hashed file. What is the procedure to do it?

any answer can be appreciated.
Ravi
kalpna
Premium Member
Premium Member
Posts: 78
Joined: Thu Feb 02, 2006 3:56 am

Post by kalpna »

use an aggregator..
group by key
retreive first(col1)

kalpna
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

As Kalpana suggested you can use aggregator to get the first row grouped by the key.

You can also use transformer to get the first row of the key using stage variables.

--Balaji S.R
ameyvaidya
Charter Member
Charter Member
Posts: 166
Joined: Wed Mar 16, 2005 6:52 am
Location: Mumbai, India

Post by ameyvaidya »

Before loading to the Hashed file, SOrt and use a transformer to select and pass out the first row for a given key value.
Amey Vaidya<i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Order your DB2 query by 'col2 descending'.
-craig

"You can never have too many knives" -- Logan Nine Fingers
AGStafford
Premium Member
Premium Member
Posts: 30
Joined: Thu Jan 16, 2003 2:51 pm

Post by AGStafford »

You can create a job like:

Code: Select all

               Hash File A Lkup
                        |
                        V
DB2 ---------> Transformer ---------> Hash File A

In the Transformer, the Constraint for Hash File A would be
If IsNull(Hash File A Lkup.field) Then @TRUE Else @FALSE

So if the row does not exist in the Hash file, write it, otherwise do not write the row. This way only the first row ends up being loaded.
Post Reply