How to assign sequence numbers to sorted data ?

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
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

How to assign sequence numbers to sorted data ?

Post by vivekreddy »

Hi.

I have this data which at present has sequence numbers which are not in order due to some data records failing to migrate to target due to validation failure, and later on passing through after being suitably corrected.
Now I first of all sort the data on the basis of a key and the timestamp of the creation of the data record to get a proper logical sequence.

Now, how can I assign the appropriate sequence numbers to each record, considering that for a given key, there can be multiple data, and I am grouping the data on the basis of the key value.

So if I have key value as A, and corresponding records as 4 in number, so they should be logically numbered as 1-4, and for another key value B with corresponding records as 5 in number, the logical numbering should be 1-5.
Considering that both groups of records are in the same dataset, can anyone suggest as to how I can achieve this logical numbering?
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hope you are using Sort stage for sorting the data in the order. User "Create Key Change column" option in the Sort stage which will enable you additional field.
This will assign 1 to each new group.
User Transformer stage to store the previous record in a stage variable and add 1 till you find the current record as 1.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hope you are using Sort stage for sorting the data in the order. User "Create Key Change column" option in the Sort stage which will enable you additional field.
This will assign 1 to each new group.
User Transformer stage to store the previous record in a stage variable and add 1 till you find the current record as 1.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hope you are using Sort stage for sorting the data in the order. User "Create Key Change column" option in the Sort stage which will enable you additional field.
This will assign 1 to each new group.
User Transformer stage to store the previous record in a stage variable and add 1 till you find the current record as 1.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
vivekreddy
Participant
Posts: 43
Joined: Mon Jan 15, 2007 10:53 pm

Post by vivekreddy »

I am sorry, but could you please elaborate as to how I may store a previous value in a stage variable, and then use it for comparison?
Regards,
Vivek D. Reddy

__________________________________________
If knowledge can create problems, it is not through ignorance that we can solve them. - Isaac Asimov
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Use stage variable in Transformer,

Code: Select all

Intial Assignment  vPreKey = 1

Counter => If Input.ChangeKeyColumn = 0 Then PreKey + 1 Else 0
vPreKey = Counter
Assing Counter to a Field.

Oh sorry, just now I notices that the post has been repeated.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

A simple search would have revealed the methodolgy. Group changes and key assingment has been discussed a number of times.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Too difficult.

Just add a Column Generator, operating sequentially, downstream of the Sort stage (which presumably was also operating sequentially, or use a Sort Merge collector if not).

Use a Cycle with an increment of 1.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply