count of the column by using loop variables

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
iskapalli
Participant
Posts: 76
Joined: Wed Jul 25, 2007 12:36 am

count of the column by using loop variables

Post by iskapalli »

Hi,

I want to caclulate count of the column by useing loop variables in transformer.

select count(col1) from the table.

But i am getting 5000 rows out of 10000.


Defined the following stage variables:

NumSavedRows
SaveInputRecord()

IsBreak
LastRow()

NumRows
IF IsBreak THEN NumSavedRows ELSE 0


Defined the following loop variable:

SavedRowIndex
GetSavedInputRecord()

Loop condition:
@ITERATION <= NumRows

Define the output link columns and their derivations:
Col1 - NumRows
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Anything in the parallel Transformer stage is per-node.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Re: count of the column by useing loop variables

Post by Kryt0n »

iskapalli wrote: I want to caclulate count of the column by useing loop variables in transformer.

select count(col1) from the table.
Why would you need to advance passed this if all you want is the count?
iskapalli wrote: Defined the following stage variables:

NumSavedRows
SaveInputRecord()

Define the output link columns and their derivations:
Col1 - NumRows
If you aren't using the input record, why save it?
Is there a requirement behind what you are doing or practising the use of looping?
iskapalli
Participant
Posts: 76
Joined: Wed Jul 25, 2007 12:36 am

Post by iskapalli »

this is the requirement. This is the first time iam implementing by useing loop variable.I am trying to give lastrow(col1).but it is not allowing. Please let me know where I am doing wrong
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

So you only want the last row of data? Just have a LastRow() condition on the output stream, run in sequential mode and sort your input... or better than that, make sure you only retrieve the row you want.

Looping is only required when you want one row to produce multiple rows so unless there is something missing in your requirement, I don't see what it is.
iskapalli
Participant
Posts: 76
Joined: Wed Jul 25, 2007 12:36 am

Post by iskapalli »

Sorry Kryt0n I will explain my requirement clearly.

job design-> td stage -> transformer-> td stage

in source I have written custom query. From this query I am extracting one
column(period). I want count of this column. For this I want to use loop variable. I hope you will get my requirement.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not really clear yet, I'm afraid. Can you post an example or twelve? What the selected data looks like and what your counted output from that input would be? That would be a good and much less ambiguous start.
-craig

"You can never have too many knives" -- Logan Nine Fingers
PhilHibbs
Premium Member
Premium Member
Posts: 1044
Joined: Wed Sep 29, 2004 3:30 am
Location: Nottingham, UK
Contact:

Post by PhilHibbs »

Loop variables are not for counting the number of rows - Loops replicate the input row a number of times on the output link, and Loop Variables are evaluated for each copy of the input row that is generated.

To count the number of rows, feed your stream through an Aggregator.

And if you really want ot do it with a Loop Variable... well, don't. That's not a sensible thing to want to do. It's like wanting to drive across a river. Sure, if you go fast enough you might make it, but the only sane solution is to use a bridge or a ferry.
Phil Hibbs | Capgemini
Technical Consultant
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You could also wait for a drought.

Meantime you can count in a Transformer stage using stage variables.
As noted, Loop variables are not the correct mechanism. Use a Loop variable for processing things within a field (though counts of those can probably more easily be obtained with functions like Count() or DCount()).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or we could wait for an example of the input and desired output so we have a better idea what "count" means in this context...
-craig

"You can never have too many knives" -- Logan Nine Fingers
iskapalli
Participant
Posts: 76
Joined: Wed Jul 25, 2007 12:36 am

Post by iskapalli »

example

input:
col1
a
b
c
d
e
f

output:
col1 col2
a 6
b 6
c 6
d 6
e 6
f 6

please help me
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Search DSXchange for "fork join". This is not a task for the Transformer stage.
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