Page 1 of 1

how to find minimum value in a column using transformer?

Posted: Sun Aug 05, 2012 11:21 pm
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

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

Posted: Mon Aug 06, 2012 12:08 am
by SURA
Seems to be like interview question.

Sortit--> use three variables --> compare it.

Posted: Mon Aug 06, 2012 12:18 am
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.

Posted: Mon Aug 06, 2012 12:30 am
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.

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

Posted: Tue Aug 07, 2012 12:30 am
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

Posted: Tue Aug 07, 2012 12:57 am
by ssreeni3
Sort the records and take a constraint as inrownum=1.It might work.

--------sreeni

Posted: Tue Aug 07, 2012 1:34 am
by jhansi
good idea sreeni.
but it gives only one record as output.

Posted: Tue Aug 07, 2012 1:40 am
by jhansi
i get this logic by putting initial value as maximum as the data type max value

Posted: Tue Aug 07, 2012 2:24 am
by ssreeni3
Give more clarity.
----Sreeni

Posted: Tue Aug 07, 2012 3:59 am
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.

Posted: Tue Aug 07, 2012 7:06 am
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.

Posted: Tue Aug 07, 2012 5:29 pm
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.