how to generate a sequence number in transformer

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
praveenk
Participant
Posts: 18
Joined: Sat Jan 15, 2011 11:31 am
Location: HYDERABAD

how to generate a sequence number in transformer

Post by praveenk »

Hi,

I'm working on datastage 7.1PX, can anyone explain me about generating a unique sequence number using transformer stage..

ThankX alot in advance
praveen
Praveen
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Welcome.

Just for grins, why the "in transformer" part of your question? Why not use the stage that exists just to generate sequence numbers - i.e. the Surrogate Key Generator stage?
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You'll find several versions of the formula here if you do an exact search for NUMPARTITIONS in the forums, which should help answer your question. This one allegedly works fine. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
nayanpatra
Participant
Posts: 41
Joined: Sat Jun 06, 2009 11:13 pm
Location: Kolkata

Post by nayanpatra »

If the surrogate key stage is not available to you, you may take the help of stage variables present in the transformer stage.

SV + 1 : SV (Initialize it to 0)

Move this SV into your surrogate key column.

So, when the first record comes the SV is set to 0. After executing the above statement, the variable will hold the value 1.

For second record, SV is set to 1. After executing the above statement, the variable will hold the value 2 and so on.

This design may work if it is a one-time run. But to incorporate it in some daily job run, you may need to take care where to initialize this variable. At the very sequence level you will have to fetch the next surrogate key value and pass it to the job. You may write a routine for this purpose. Say you have stored this value in the job parameter NSK. Now you need to add another job parameter as

NSK + SV : SV1

Now move this SV1 in the surrogate key column.

Hope this helps you solve the problem. Let me know the outcome.
Nayan
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The outcome will be a consecutive sequence of the same numbers on every node in the configuration. No uniqueness.
Have the sequence start with the partition number (possibly with a constant offset) and be incremented by the (constant) partition count.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
mgendy
Premium Member
Premium Member
Posts: 44
Joined: Thu Sep 10, 2009 5:30 am
Contact:

you should use sequential mode

Post by mgendy »

the Surrogate Key will do the same behavior if it is operat in parallel , to resolve that you should use either the Surrogate Key or the Tansformer in sequential mode
Mohmmed Elgendy
Senior System Analyst
Data IntegrationTeam
Etisalat Egypt
+20 1118511161
praveenk
Participant
Posts: 18
Joined: Sat Jan 15, 2011 11:31 am
Location: HYDERABAD

Re: how to generate a sequence number in transformer

Post by praveenk »

I have a requirement of implementing scd type2 where i want to insert the previous record and the updated record, in which i dont want to disable constraints, so for this i want to make use of composite primarykey for the key column and uniue sequence number.

pls guide me
Praveen
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: you should use sequential mode

Post by chulett »

mgendy wrote:the Surrogate Key will do the same behavior if it is operat in parallel , to resolve that you should use either the Surrogate Key or the Tansformer in sequential mode
If you are saying that the Surrogate Key Generator stage will "do the same" if not run sequential, as in not produce unique numbers across partitions, that would be incorrect. Unless that's a failing of the early 7.1 version of it, hard to remember that far back. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: how to generate a sequence number in transformer

Post by chulett »

praveenk wrote:I have a requirement of implementing scd type2 where i want to insert the previous record and the updated record, in which i dont want to disable constraints, so for this i want to make use of composite primarykey for the key column and uniue sequence number.
I don't see how any of that precludes you from using the Surrogate Key Generator stage for the "unique sequence number" part. Regardless, there are already of couple of posts here on how to generate one in a transformer, what other quidance do you need?
-craig

"You can never have too many knives" -- Logan Nine Fingers
mgendy
Premium Member
Premium Member
Posts: 44
Joined: Thu Sep 10, 2009 5:30 am
Contact:

Re: you should use sequential mode

Post by mgendy »

chulett wrote:
mgendy wrote:the Surrogate Key will do the same behavior if it is operat in parallel , to resolve that you should use either the Surrogate Key or the Tansformer in sequential mode
If you are saying that the Surrogate Key Generator stage will "do the same" if not run sequential, as in not produce unique numbers across partitions, that would be incorrect. Unless that's a failing of the early 7.1 version of it, hard to remember that far back. :?
Exactly thats what i mean , i tried it before and get that result may be for srot or partitioning problem , but that was the result
Mohmmed Elgendy
Senior System Analyst
Data IntegrationTeam
Etisalat Egypt
+20 1118511161
srinivas.nettalam
Participant
Posts: 134
Joined: Tue Jun 15, 2010 2:10 am
Location: Bangalore

Post by srinivas.nettalam »

you can use the formula below

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

map this to your target column
N.Srinivas
India.
Post Reply