Page 1 of 1

sequence numbers for a group of keys

Posted: Wed Dec 30, 2009 2:38 am
by dnat
Hi,

I want to generate sequence numbers of a group of keys

My input records are like this

Col A|Col B|Col c

aaa|bbb|ccc
aaa|bbb|ccc
ddd|dfd|sdc
sds|oio|pop

I want the output like

Col A|Col B|Col c|Col D

aaa|bbb|ccc|1
aaa|bbb|ccc|2
ddd|dfd|sdc|1
sds|oio|pop|1

How can i achieve this..

Posted: Wed Dec 30, 2009 3:04 am
by nikhilanshuman
Hi,
Put a sort stage after the source stage.In the sort stage,there is a property "Create cluster key change column".There,add your group of columns.
Here,the "change_key" value for you data will be : 1,0,1,1
(1 is for new and 0 if the data is repeated.)

aaa|bbb|ccc|1
aaa|bbb|ccc|0
ddd|dfd|sdc|1
sds|oio|pop|1

Now,take a transformer.In the transformer,take one stage variables say cur_count.

Following is the derivation for cur_count :
if link1.change_key=1 then 1 else cur_count+1

In the above,for new records,if the value of change_key is 1 then cur_cnt will be 1.If it is zero,the count will be incremented by 1.If a new record comes,the value of cur_count will be reset to 1.

Now,the stage variable cur_count contains the expected count.