Page 1 of 1

Help with the code

Posted: Thu Apr 15, 2010 10:42 am
by wittyme
There are like 1000 rows and I need a new column with simultaneous 100 and 200 and each row...

like the new column should be

100
200
100
200

How to get to this...

Posted: Thu Apr 15, 2010 10:46 am
by anbu
Do you have any criteria for a row to have 100 or 200?

Posted: Thu Apr 15, 2010 10:49 am
by wittyme
Not really... I am getting duplicate 100 and 200 values from my source. So, I want to add it in the job.

No criteria specifically.

Posted: Thu Apr 15, 2010 11:08 am
by chowdhury99
It does not make sense to get same 2 columns. Anyway, you may map source column to both target column.

Thanks

Posted: Thu Apr 15, 2010 3:37 pm
by Kryt0n
Completely random 100 and 200 values? Or duplicating a source row so that you have one with 100 and the other with 200? Other?

For former, a round robin partitioner and then base the new column on @PARTITIONNUM or stage variables (if 100 then 200 else 100 although that won't necessarily be balanced unless using single partition). For duplicating source rows, send through a copy stage with two outputs and then through a column generator on each link, one setting to 100, the other to 200. For other...

Posted: Thu Apr 15, 2010 4:23 pm
by ray.wurlod
I think you mean "alternating" rather than "simultaneous".

If the Transformer stage is operating in Sequential mode, then all you need are two stage variables, one to remember the previous row and the other to toggle the value.

Once you get to parallel operation you have to answer more questions, such as does it matter whether the partitions are processed independently (which might mean that you end up with slightly more 100 values than 200 values particularly if each partition processes an odd number of rows).

Posted: Thu Apr 15, 2010 4:25 pm
by ray.wurlod
Actually you could do it with one uint8 stage variable whose initial value is not 100.

Code: Select all

svValue  <--  If svValue <> 100 Then 100 Else 200

Posted: Fri Apr 16, 2010 2:35 am
by Sainath.Srinivasan
wittyme wrote:Not really... I am getting duplicate 100 and 200 values from my source. So, I want to add it in the job.

No criteria specifically.
What will happen in the following case ?
Key
Tom
Jerry
Jerry
Jerry
Tom
You will get
GenValue Key
100 Tom
200 Jerry
100 Jerry
200 Jerry
100 Tom
Is that what you want ?

Posted: Fri Apr 16, 2010 3:58 pm
by wittyme
hmmm... yeah... similar case