Sunday, January 27, 2013

Counter Using Transformer


In a parallel job  a unique counter is generated by using special parallel macros.
  
1.  Create a stage variable for the counter, eg. SVCounter.  

2.  At the Stage Properties form set the Initial Value of the Stage Variable to 
"@PARTITIONNUM - @NUMPARTITIONS + 1".

3.Set the derivation of the stage variable to "svCounter + @NUMPARTITIONS". 

4.Create a column(counter) in the output of the Transformer and  set the derivation of the column(counter) to svCounter(stage variable)

 For 4 node configuration each instance will start at a different number, eg. -3, -2,-1,0 When the counter is incremented each instance is increment by the number of partitions, eg. 4. This gives us a sequence in instance 1 of 1, 5, 9, 13... Instance 2 is 2, 6, 10, 14... etc.In this process the counter will always start from 1.This method only works if the input data is evenly balanced i.e. equal number of rows going through each partition.

In 8.5 version  developer can generate the unique counter(Surrogate Key) by using Surrogate Key tab in the transformer.User need to mention database sequence name and database crendentials where database sequence name is created.

2 comments:

  1. I would like to know if you could help me out. I have a a file with 2 columns (TABLENAME and CLOB) and in the TABLENAME there are "Providers". I would like to know how to set them at number 5000 and then increment them, per provider. So if I have 5 providers per file, it would be 5000, 5001, 5002, 5003, 5004. This is a daily file so we will get a file everyday. So Day 2, the 1st provider must be 5005 since 5004 was the last file from the example. Any help would be great. Thanks

    ReplyDelete
  2. I would like to know if you could help me out. I have a a file with 2 columns (TABLENAME and CLOB) and in the TABLENAME there are "Providers". I would like to know how to set them at number 5000 and then increment them, per provider. So if I have 5 providers per file, it would be 5000, 5001, 5002, 5003, 5004. This is a daily file so we will get a file everyday. So Day 2, the 1st provider must be 5005 since 5004 was the last file from the example. Any help would be great. Thanks

    ReplyDelete