You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Jonathan Coveney <jc...@gmail.com> on 2011/05/20 19:42:11 UTC

How to make a UDF that can take a variable number of arguments while using getArgToFuncMapping?

My goal is to be able to make functions like GREATER(a,b,c...) which can
take any number of columns, and for each row will give the greater of them.
I also want to detect what type of columns they are, and use IntGREATER or
DoubleGREATER or whatever.

A) has someone done something like this?
B) If not, how can I specify the correct Schema for getArgToFuncMapping?
Ideally it could just detect the schema of the first and go off of that, but
it looks like you have to match it directly... I tried overloading the
schema GREATER (where getArgTofuncMapping lives) and then using that to
figure out how many fields there are, but that didn't work. Should this
approach work? IE is getSchema called before getArgToFuncMapping? Is there a
cleaner way to do this?

Thanks for your help!
Jon

Re: How to make a UDF that can take a variable number of arguments while using getArgToFuncMapping?

Posted by Thejas M Nair <te...@yahoo-inc.com>.
As a workaround , you can use - MAX(TOBAG(a,b,c));

For example , if a,b,c columns are of type int. Then, TOBAG(a,b,c) will have a schema of bag of integers, and the org.apache.pig.builtin.IntMax class will get used.

-Thejas




On 5/20/11 11:24 AM, "Daniel Dai" <ji...@yahoo-inc.com> wrote:

It is not yet supported. See https://issues.apache.org/jira/browse/PIG-1577

Daniel

On 05/20/2011 10:42 AM, Jonathan Coveney wrote:
> My goal is to be able to make functions like GREATER(a,b,c...) which can
> take any number of columns, and for each row will give the greater of them.
> I also want to detect what type of columns they are, and use IntGREATER or
> DoubleGREATER or whatever.
>
> A) has someone done something like this?
> B) If not, how can I specify the correct Schema for getArgToFuncMapping?
> Ideally it could just detect the schema of the first and go off of that, but
> it looks like you have to match it directly... I tried overloading the
> schema GREATER (where getArgTofuncMapping lives) and then using that to
> figure out how many fields there are, but that didn't work. Should this
> approach work? IE is getSchema called before getArgToFuncMapping? Is there a
> cleaner way to do this?
>
> Thanks for your help!
> Jon




--


Re: How to make a UDF that can take a variable number of arguments while using getArgToFuncMapping?

Posted by Daniel Dai <ji...@yahoo-inc.com>.
It is not yet supported. See https://issues.apache.org/jira/browse/PIG-1577

Daniel

On 05/20/2011 10:42 AM, Jonathan Coveney wrote:
> My goal is to be able to make functions like GREATER(a,b,c...) which can
> take any number of columns, and for each row will give the greater of them.
> I also want to detect what type of columns they are, and use IntGREATER or
> DoubleGREATER or whatever.
>
> A) has someone done something like this?
> B) If not, how can I specify the correct Schema for getArgToFuncMapping?
> Ideally it could just detect the schema of the first and go off of that, but
> it looks like you have to match it directly... I tried overloading the
> schema GREATER (where getArgTofuncMapping lives) and then using that to
> figure out how many fields there are, but that didn't work. Should this
> approach work? IE is getSchema called before getArgToFuncMapping? Is there a
> cleaner way to do this?
>
> Thanks for your help!
> Jon