How to generate sequence numbers within a sorted list

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
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Post by asorrell »

How many rows? For small to medium sized row counts, the easiest way is to run the job in sequential mode and sort the data prior to entering the transformer. Just use @ROWNUM to generate your numbers.
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
deeplind07
Participant
Posts: 31
Joined: Mon Jun 28, 2010 5:15 am
Location: pune

Post by deeplind07 »

Hash Partition (on F1 )and sort(and f1 and f3) in the input link of transformer.
Use following stage variables in the transformer.
Default value of all stage varibles should be 0

SVF1_1=F1
IF SVF11=SVF12 THEN SVF2= SVF2+1 ELSE 1
SVF12=SVF11
sec105105
Participant
Posts: 44
Joined: Fri Mar 20, 2009 7:21 am
Location: Ottawa

Post by sec105105 »

deeplind07 wrote:Hash Partition (on F1 )and sort(and f1 and f3) in the input link of transformer. ...
SVF1_1=F1
IF SVF11=SVF12 THEN SVF2= SVF2+1 ELSE 1
SVF12=SVF11
Something similar to the above worked. Thanks!
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hopefully something similar but with better stage variable names. :wink:

FYI - this is old school stage variable usage for resetting a counter while doing group change detection. And the first variable isn't really needed but can be helpful if your 'group' consists of multiple fields. And as with all things Stage Variable, order matters as they evaluate top down.

Code: Select all

svCounter: If F1 = svOldF1 then svCounter+1 else 1
svOldF1 = F1
You can simplify the group check by letting a Sort stage do that for part for you. If you've done that you'll have a new field called KeyChange that is set to True on the first entry of a group. So the code becomes:

Code: Select all

svCounter: If KeyChange then 1 else svCounter+1
-craig

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