Surrogate Key Generation in PX

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
shivakumar
Participant
Posts: 31
Joined: Wed Mar 17, 2004 3:33 am

Surrogate Key Generation in PX

Post by shivakumar »

Hi ,

I have to create a surrogate key for a target table by taking the maximum value from the same target table.

For example I get the Maximum value as 100 now I have to insert the values starting from 101 for this I am using the Transformer stage for incrementing the values the Logic is MAXVALUE+INROWNUM.

In the PX the inrow num is not proper because based on the Partitions it is givinig the same rownumbers for next partition.

For Eg

Partion Number Row Number Max(Value)+Rownum
1 1 101
1 2 102

2 1 101
2 2 102

Can you please help me out.

Regards
Shiva


How Can I resolve this
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

1st get the maximum value (say MAX_SURG) of surrogate key from the target, for this you may write a routine to parse a single SQL) .

now use surrogate key generator stage, with start value of MAX_SURG+1
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Add 'PartitionNum' to the RowNum to get the unique value across partitions.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You have two ways of doing it. The surrogate key generator stage does handle the multiple partitions to give you unique numbers. You can mimic this in a transformer stage variable following the instructions in the FAQ forum on creating a parallel counter.
kool78
Participant
Posts: 104
Joined: Sat Aug 20, 2005 2:02 pm

Post by kool78 »

one of the best possible methods would be using "Oracle Sequence".
"Attitude always and almost determines the altitude of your Life"
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

kool78 wrote:one of the best possible methods would be using "Oracle Sequence".
how you will use the oracle sequence, will you give a oracle call for each row, or you will write a before insert trigger??

what is it is a teradata table or any other batabase or if you want to write in a csv file etc.
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

Not a fan of the database generated keys unless you have multiple products loading at the same time. The DataStage generated keys do a good job. See my comments at: Why database generated surrogate keys drive me nuts!!!
Post Reply