how to find minimum value in a column using transformer?

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
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

how to find minimum value in a column using transformer?

Post by jhansi »

i am trying to find minimum value in a column using transformer.
my data is like this
marks
45
56
90
65
80

i applied below logic.i have taken 2 stage variables.
varmin -->i drag the marks column to this.
cmp -->Min(varmin,cmp)
but i am getting all zero's in output column.
can anyone please help me in this problem

thnx in advnce
jhansi
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: how to find minnimun value in a column using transformer

Post by SURA »

Seems to be like interview question.

Sortit--> use three variables --> compare it.
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That's not what the Min() function does. Check the documentation to find out what the Min() function does.

The solution is most easily wrought using a pair of stage variables that you use to compare the value with its value in the previous row, and update only if it is smaller.

It is not necessary to sort the data for Minimum.
However if you require the overall minimum and to process in parallel, you need to partition by this column (so that all instances of each value are on the same node as each other), then use a sort-merge Collector into a Head or Tail stage and use that to capture the overall minimum from the minima from each node.

Actually, if you sort your data (subject to the same partitioning consideration as above), you can simply take the first or last from the sorted set.
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 »

ray.wurlod wrote:The solution is most easily wrought using a pair of stage variables
Seems to me that a single one would do the trick.
-craig

"You can never have too many knives" -- Logan Nine Fingers
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

Re: how to find minnimun value in a column using transformer

Post by jhansi »

when i am using 3 stage variables.it is is giving output like this
0
45
56
65
65
logic:
i hav taken 3 stg variables.
i draged marks col in to 1st & 3rd vars.
in 2 nd var i write
if stg1<stg2 then stg1 else stg2
but i am expecting 45 as final value
jhansi
ssreeni3
Participant
Posts: 29
Joined: Fri May 18, 2012 1:35 am

Post by ssreeni3 »

Sort the records and take a constraint as inrownum=1.It might work.

--------sreeni
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

Post by jhansi »

good idea sreeni.
but it gives only one record as output.
jhansi
jhansi
Participant
Posts: 33
Joined: Sat May 26, 2012 4:56 am

Post by jhansi »

i get this logic by putting initial value as maximum as the data type max value
jhansi
ssreeni3
Participant
Posts: 29
Joined: Fri May 18, 2012 1:35 am

Post by ssreeni3 »

Give more clarity.
----Sreeni
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Initialize stage variable to a very large value.
As each row is processed compare the column to the stage variable.
If the value in the column is less than the value in the stage variable, replace the stage variable's value with that value.
Once the last row has been processed the stage variable (and the output column to which it is linked) will contain the smallest value.
However see earlier notes about parallel execution.
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 »

jhansi wrote:but it gives only one record as output.
You haven't said how many output records you need nor what you want them to look like. If you need all input records output with the overall minimum value, that's an entirely different process than what we've been discussing.

As noted, need more clarity.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

jhansi wrote:but it gives only one record as output.
There IS only one minimum value in the sample data you posted.
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