Composite keys in hashed files

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
mleroux
Participant
Posts: 81
Joined: Wed Jul 14, 2004 3:18 am
Location: Johannesburg, South Africa
Contact:

Composite keys in hashed files

Post by mleroux »

Are there any special considerations when using a composite key (multiple key columns) in a hashed file?

I looked at a job where one of the hashed file lookups wasn't giving any matching rows, even though the keys in both the lookup and input stages were corresponding perfectly. The lookups that were working fine had only one key column each, whereas the problematic hashed file had two (contiguous) key columns.

I modified the job to use a single, concatenated key column (Keyvalue1 : ":" : Keyvalue2) which then worked fine.

Tried a search in the documentation and on DSXchange, but couldn't really find anything. I don't think I've ever had to work with a composite key in a hashed file but it seems strange that it would be problematic.

Can one use composite keys in hashed files? If so, any ideas as to why the job in question was problematic?
Morney le Roux

There are only 10 kinds of people: Those who understand binary and those who don't.
andru
Participant
Posts: 21
Joined: Tue Mar 02, 2004 12:25 am
Location: Chennai

Post by andru »


Hash Files can have composite keys. I have worked with lots of hash files with composite key. Sometime, hash file lookup doent return proper values if you do a lookup on a integer column. That necessitates to convert the integers to char field and then perform the lookup.
It would have worked for you when you concatenate composite keys because, it would consider the int as char when you concatenate them.
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

Multiple lookup keys in a hash file is no problem. Just remember that DataStage always does a string compare on the key fields. Use the key expression to format the lookup value to EXACTLY the same format that is stored in the hash file.

For example, you may need to trim excess space characters in a varchar. (e.g. "ABC " does not match "ABC")

You may need to fmt numeric values. (e.g. "1.00" does not match "1")

The most common problem that I see is a metadata mismatch between the process that creates the hash file and the process that does a lookup on the hash file. If the metadata does not match, the lookup will almost always fail.

Mike
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

If you create a composite key in a job then the separator is @TM. There are ways around this but that is the default. So your key should be:

Code: Select all

Key = KeyField1 : @TM : KeyField2
This has been covered lots of times but maybe under "compound keys" or "muti-part keys". Might be hard to search for. Ray has discussed them in great detail. I am sure there is a Full Wurlod on it out there somewhere.
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

When you're using a Hashed File stage there are no special considerations. The stage (with the underlying engine) looks after everything. All you have to do is to make sure you've identified ALL the key columns accurately.

As will all hashed file metadata (whether single or multiple key), the Position of the key column(s) is 0, the position of the non-key columns is a positive integer. These must correspond to the definitions in the hashed file dictionary (that is, its metadata).

You only need to be concerned about the key separator character if you're reading the hashed file with DataStage BASIC. It's only then that you have to build the physical representation of the key.

Pretty sure that there is a post about this stuff, though indirect. Try a search for "@KEY_SEPARATOR".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
FanWeik
Participant
Posts: 10
Joined: Mon Apr 26, 2004 11:40 am
Location: Seattle WA

Post by FanWeik »

Hello,

I also need to do a lookup with a 2-part key in a PX job agaist a DB2 table. I concatenated the 2 fields in the Lookup stage in the format that's mentioned (Keyvalue1 : ":" : Keyvalue2). The compile was ok but the run generated the following error.

main_program: Syntax error: Error in "lookup" operator: Error in input redirection: Error in input parameters: Error in view adapter: Error in binding: Error in field type: Expected identifier; got: "":"", line 91
Expected operator name, got: ")", line 97; text: copy

Thanks for your help!!
Fan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've moved way off topic! In general you don't use hashed files in PX, and your post indicates that you want to perform a lookup in PX.

Ideally, post the question on the PX forum.

Basically, though, you no longer create a composite key - that's purely for hashed file. Instead, you declare as many key columns as there are key columns in the probe table.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chucksmith
Premium Member
Premium Member
Posts: 385
Joined: Wed Jun 16, 2004 12:43 pm
Location: Virginia, USA
Contact:

Post by chucksmith »

Back to hash files. You may want to verify that the key structure of the hash file actually matches what you find on your columns tab. You can list the dictionary (metadata) of the hash file at the command prompt in DataStage Administrator using the

Code: Select all

LIST DICT YourHashFileName
command. Verify that all columns you think are part of the key are also considered that in the dictionary. If not, the easiest thing to do is delete the hash file and recreate it.

This often happens if the primary key columns change after the hash file is initially created.
Post Reply