hadoop-pig-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Gates <ga...@yahoo-inc.com>
Subject Re: UDF with parameters?
Date Fri, 22 May 2009 22:52:06 GMT
Yes, it is possible.  The UDF should take the percentage you want as a  
constructor argument.  It will have to be passed as a string and  
converted.  Then in your Pig Latin, you will use the DEFINE statement  
to pass the argument to the constructor.

REGISTER /src/myfunc.jar
DEFINE percentile myfunc.percentile('90');
A = LOAD 'students' as (name, gpa);
B = FOREACH A GENERATE percentile(gpa);

See http://hadoop.apache.org/pig/docs/r0.2.0/piglatin.html#DEFINE for  
more details.


On May 22, 2009, at 3:37 PM, Brian Long wrote:

> Hi,
> I'm interested in developing a PERCENTILE UDF, e.g. for calculating a
> median, 99th percentile, 90th percentile, etc. I'd like the UDF to be
> parametric with respect to the percentile being requested, but I  
> don't see
> any way to do that, and it seems like I might need to create  
> PERCENTILE_90, etc type UDFs explicitly, versus being able to do  
> something
> like GENERATE PERCENTILE(90, duration)
> I'm new to Pig, so I might be missing the way to do this... is it  
> possible?
> Thanks,
> Brian

View raw message