Conditional lookup using hased 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
ekareem
Participant
Posts: 17
Joined: Wed Aug 27, 2003 7:10 pm

Conditional lookup using hased files

Post by ekareem »

Hi,
I want to simulate the following logic in 1 transformer:

If data is found after hash1 lookup then
move data from hash1 to output
Else
lookup hash file 2
If data is found in hash2
move data from hash2 to output
Else
move 'not found' to output
End If

Any suggestions? Thanks.
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

If data is single column then using stage variables you can achieve it (using a single target link).
If it's not then you would need to create three links from the transformer writing to the same target.
First link would be used if NOT(lkp1.NOTFOUND) is ture.
Second link would be used if lkp1.NOTFOUND and NOT(lkp2.NOTFOUND) is true.
Third would be used if lkp1.NOTFOUND and lkp2.NOTFOUND is true.

Hope this will help you.
Success consists of getting up just one more time than you fall.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

There are no conditional lookups.

You could consider using transformers with link collectors to simulate a conditional lookup effect.

Do the first lookup, and based on the result send to two different output links. The first output link acts as if the lookup was found, the second is the lookup not found. Send the first output link to a link collector. From the second output link, go to another transformer and do the second lookup. Send this output to the link collector as well. Now you have the conditional lookup.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or just have it do both lookups and check them in the proper order. No need for stage variables or extra links, really.

For something as simple as this I don't see a need to go to the trouble of Link Collectors and all that, but it should be kept in mind for the future. Your post has almost the exact logic you would leverage, you just need to move past the perceived need for the lookup to be 'conditional'. :wink: The 'condition' is enforced by the order you check each link for success.

Well, unless there is a tremendous amount of overhead involved in on or both of the lookups and they really affect the performance of the job - then consider the methodology Ken mentions.
-craig

"You can never have too many knives" -- Logan Nine Fingers
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Post by loveojha2 »

Or just have it do both lookups and check them in the proper order.
The 'condition' is enforced by the order you check each link for success.
Hi Chulett,
ekareem wants to get the data from the two different Hashed lookup files (not from the source). Do you mean that its possible through only one output link? :? I am not able to understand it. :oops: Can you please explain, how would you achieve that?

Thanks
Success consists of getting up just one more time than you fall.
jenkinsrob
Participant
Posts: 31
Joined: Mon Dec 01, 2003 6:24 am
Location: London

Post by jenkinsrob »

Just have lookups to both hash files from your single transformer.

Then in the derivation of the output link use the following kind of logic:

If Not(IsNull(Hash1_Lkp)) Then Hash1_lkp Else If Not(IsNull(Hash2_Lkp)) Then Hash2_lkp Else 'Not Found'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Exactly.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

The original subject, "Condition lookup", means that the second lookup is only attempted should the first lookup meet a condition. All lookups in a single tranformer are always attempted. Constraints have no impact whether a reference SQL is fired or a hash reference read is made.

The only method to do a conditional lookup is thru separation of conditions and use of transformers with constraints to divide the rows and send them on for further processing and lookup, with the rows meeting earlier conditions bypassing that subsequent logic. The link collectors are the method for bringing the rows back together.

It's nasty looking, but the only method to make a reference a condition. Personally, I like the cleaner design approach.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

kcbland wrote:The original subject, "Condition lookup", means that the second lookup is only attempted should the first lookup meet a condition. All lookups in a single tranformer are always attempted. Constraints have no impact whether a reference SQL is fired or a hash reference read is made.
Never said that they did. And as you noted, there is no such thing (unless you go 390). Just trying to point out that in this case, as in most cases when someone says they 'need a conditional lookup'... they really don't. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

chulett wrote:when someone says they 'need a conditional lookup'... they really don't. :wink:
Yup, I agree. 8)
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Conditional lookups are fully supported in the parallel Lookup stage. Who was asleep during class? :lol:

A server job solution to implement true conditional lookups would require at least two Transformer stages.

You can do it with one Transformer stage and two reference input links, but both lookups will be performed unconditionally. You then need to create constraint expressions to detect what happened and to control data flows accordingly.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ray.wurlod wrote:Conditional lookups are fully supported in the parallel Lookup stage. Who was asleep during class? :lol:
Hey, we weren't discussing parallel jobs. Besides, it was too flipping cold to fall asleep... well, except maybe from hypothermia. :wink:
-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 »

We weren't discussing 390 either, but I had to challenge your assertion! :wink:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ah... 390. Was pointing that out because that version has a stage that is actually called the 'Conditional Lookup' stage. :wink:
-craig

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