generating seq nos

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
dnat
Participant
Posts: 200
Joined: Thu Sep 06, 2007 2:06 am

generating seq nos

Post by dnat »

Hi,

I am trying to generate uniq ids for the data i am inserting.

i know that there are lot of ways to achieve it, but i will be running the jobs parallely so i think there will be a problem.

If i use the max(col) and pass it as a variable to the job and use @OUTROWNUM , then if parallely i run many jobs , the same uniq ids will be created.

it will be the same if i store the max value in a file or take it from sequence object.

Can anyone help.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

In parallel @OUTROWNUM starts from 1 on every node. Prefer a stage variable or generated column that is initialized to the partition number (0, 1, 2, 3 for example) and incremented by the number of partitions (4 for example).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Scope
Premium Member
Premium Member
Posts: 63
Joined: Wed Jun 06, 2007 6:38 am
Location: Chennai

Post by Scope »

Try this.

(@INROWNUM * @NUMPARTITIONS) - @PARTITIONNUM

This will generate unique numbers.
Kumarez
shalini11
Participant
Posts: 74
Joined: Thu Jan 22, 2009 3:00 am

Post by shalini11 »

Pass (max(col)+1) as a job parameter and then use this parameter in Surrogate key Generator. Give the start value as the value of this parameter.
dnat
Participant
Posts: 200
Joined: Thu Sep 06, 2007 2:06 am

Post by dnat »

i can get uniq nos not a problem. but when multiple jobs run at the same time all will query the database and get the max(col)+1 value, which will be same and when they calculate unique values, all will have the same values and cannot insert if it is a primary key for the output table.

i want to have some lock sort of thing while getting the max(col)+1 value.
Jasti
Participant
Posts: 44
Joined: Sat Apr 14, 2007 6:34 am
Location: Hyderabad, India

Post by Jasti »

i can get uniq nos not a problem. but when multiple jobs run at the same time all will query the database and get the max(col)+1 value, which will be same and when they calculate unique values, all will have the same values and cannot insert if it is a primary key for the output table.
You need to run that sql to get the max(col)+1 on the target table of your job. If the target tables are different for all those jobs, you will get different values as output from that sql for sure.
Thanks,
Mohan.A.Jasti.
dnat
Participant
Posts: 200
Joined: Thu Sep 06, 2007 2:06 am

Post by dnat »

my target tables are same for multiple jobs.

so if i start the jobs parallely then i will get the same value for all the jobs as input.
wahi80
Participant
Posts: 214
Joined: Thu Feb 07, 2008 4:37 pm

Post by wahi80 »

dnat wrote:my target tables are same for multiple jobs.

so if i start the jobs parallely then i will get the same value for all the jobs as input.
I would think creating a sequence at DB end would be another option
So any record you insert into the table the DB would create the id. In DS would be much tougher, since you have to ensure that number don't overlap.

If you still want to do it in DS, then maybe when you pass max number to each job, you should increment it by diff values. e.g:
Job1 start numbers at max , Job 2 start at max+ 10000000

But I would prefer the DB way, In second option you will have to be careful about the increments
dsedi
Participant
Posts: 220
Joined: Wed Jun 02, 2004 12:38 am

Post by dsedi »

Scope wrote:Try this.

(@INROWNUM * @NUMPARTITIONS) - @PARTITIONNUM

This will generate unique numbers.
This will not work correctly. I checked that by a sample design.
The below one is the working one..

@PARTITIONNUM + (@NUMPARTITIONS * (@INROWNUM - 1)) + 1

Thought of updating this. It might be useful for some one...
pprakash
Participant
Posts: 3
Joined: Thu Aug 09, 2012 11:14 am
Location: Bangalore

Post by pprakash »

[quote="Scope"]Try this.
Last edited by pprakash on Mon Oct 29, 2012 12:46 am, edited 2 times in total.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That's already been noted and corrected three years ago. Not sure what good posting it again does.
-craig

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