You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Anil Barfa <ba...@gmail.com> on 2011/11/28 08:56:17 UTC
Passing parameter to UDF
Hi
I am using java UDF with pig. I want pass file name to UDF. I have done it
as follows but it is not working.
PIg script
REGISTER myjar.jar;
DEFINE myfun myjar.PigClass('/home/myfile.txt');
--load input data
InputValue = LOAD '$input' AS (val1,val2,val3);
InputWithMeta = FOREACH InputValue GENERATE myfun(val1,val2,val3);
Java code PigClass.java
class PigClass extends EvalFunc<Tuple>
{
public PigClass(String strPath)
{
}
public Tuple exec(Tuple input ) throws IOException {
}
};
I am getting following Error.
*<file MyScript.pig, line 7, column 45> Failed to generate logical plan.
Nested exception: java.lang.RuntimeException: could not instantiate '
myjar.PigClass**' with arguments '[/home/myfile.txt]'*
Thanks and Regards
Anil Barfa
Re: Passing parameter to UDF
Posted by Anil Barfa <ba...@gmail.com>.
Thanks Alan,
Big mistake i have made 'not declare constructor public'.
Its working fine....
On Tue, Nov 29, 2011 at 6:54 AM, Alan Gates <ga...@hortonworks.com> wrote:
> Does PigClass have a constructor that takes a single String? Can you
> share the code for your UDF?
>
> Alan.
>
> On Nov 28, 2011, at 12:26 AM, Anil Barfa wrote:
>
> > Thanks Prashant,
> > I am using 'Apache Pig version 0.8.0'.
> > package name is correct.
> > It work correct if i remove constructor (i.e if remove constructor and
> > remove '--define' from pig script.)
> >
> >
> >
> > On Mon, Nov 28, 2011 at 1:41 PM, Prashant Kommireddi <
> prash1784@gmail.com>wrote:
> >
> >> What version of Pig are you using? Can you make sure the package
> name/path
> >> "myjar.PigClass" is correct.
> >>
> >> On Sun, Nov 27, 2011 at 11:56 PM, Anil Barfa <ba...@gmail.com>
> wrote:
> >>
> >>> Hi
> >>> I am using java UDF with pig. I want pass file name to UDF. I have done
> >> it
> >>> as follows but it is not working.
> >>>
> >>> PIg script
> >>>
> >>> REGISTER myjar.jar;
> >>> DEFINE myfun myjar.PigClass('/home/myfile.txt');
> >>>
> >>> --load input data
> >>> InputValue = LOAD '$input' AS (val1,val2,val3);
> >>>
> >>> InputWithMeta = FOREACH InputValue GENERATE myfun(val1,val2,val3);
> >>>
> >>>
> >>> Java code PigClass.java
> >>>
> >>> class PigClass extends EvalFunc<Tuple>
> >>> {
> >>> public PigClass(String strPath)
> >>> {
> >>> }
> >>> public Tuple exec(Tuple input ) throws IOException {
> >>> }
> >>> };
> >>>
> >>> I am getting following Error.
> >>>
> >>> *<file MyScript.pig, line 7, column 45> Failed to generate logical
> plan.
> >>> Nested exception: java.lang.RuntimeException: could not instantiate '
> >>> myjar.PigClass**' with arguments '[/home/myfile.txt]'*
> >>>
> >>>
> >>> Thanks and Regards
> >>> Anil Barfa
> >>>
> >>
>
>
Re: Passing parameter to UDF
Posted by Alan Gates <ga...@hortonworks.com>.
Does PigClass have a constructor that takes a single String? Can you share the code for your UDF?
Alan.
On Nov 28, 2011, at 12:26 AM, Anil Barfa wrote:
> Thanks Prashant,
> I am using 'Apache Pig version 0.8.0'.
> package name is correct.
> It work correct if i remove constructor (i.e if remove constructor and
> remove '--define' from pig script.)
>
>
>
> On Mon, Nov 28, 2011 at 1:41 PM, Prashant Kommireddi <pr...@gmail.com>wrote:
>
>> What version of Pig are you using? Can you make sure the package name/path
>> "myjar.PigClass" is correct.
>>
>> On Sun, Nov 27, 2011 at 11:56 PM, Anil Barfa <ba...@gmail.com> wrote:
>>
>>> Hi
>>> I am using java UDF with pig. I want pass file name to UDF. I have done
>> it
>>> as follows but it is not working.
>>>
>>> PIg script
>>>
>>> REGISTER myjar.jar;
>>> DEFINE myfun myjar.PigClass('/home/myfile.txt');
>>>
>>> --load input data
>>> InputValue = LOAD '$input' AS (val1,val2,val3);
>>>
>>> InputWithMeta = FOREACH InputValue GENERATE myfun(val1,val2,val3);
>>>
>>>
>>> Java code PigClass.java
>>>
>>> class PigClass extends EvalFunc<Tuple>
>>> {
>>> public PigClass(String strPath)
>>> {
>>> }
>>> public Tuple exec(Tuple input ) throws IOException {
>>> }
>>> };
>>>
>>> I am getting following Error.
>>>
>>> *<file MyScript.pig, line 7, column 45> Failed to generate logical plan.
>>> Nested exception: java.lang.RuntimeException: could not instantiate '
>>> myjar.PigClass**' with arguments '[/home/myfile.txt]'*
>>>
>>>
>>> Thanks and Regards
>>> Anil Barfa
>>>
>>
Re: Passing parameter to UDF
Posted by Anil Barfa <ba...@gmail.com>.
Thanks Prashant,
I am using 'Apache Pig version 0.8.0'.
package name is correct.
It work correct if i remove constructor (i.e if remove constructor and
remove '--define' from pig script.)
On Mon, Nov 28, 2011 at 1:41 PM, Prashant Kommireddi <pr...@gmail.com>wrote:
> What version of Pig are you using? Can you make sure the package name/path
> "myjar.PigClass" is correct.
>
> On Sun, Nov 27, 2011 at 11:56 PM, Anil Barfa <ba...@gmail.com> wrote:
>
> > Hi
> > I am using java UDF with pig. I want pass file name to UDF. I have done
> it
> > as follows but it is not working.
> >
> > PIg script
> >
> > REGISTER myjar.jar;
> > DEFINE myfun myjar.PigClass('/home/myfile.txt');
> >
> > --load input data
> > InputValue = LOAD '$input' AS (val1,val2,val3);
> >
> > InputWithMeta = FOREACH InputValue GENERATE myfun(val1,val2,val3);
> >
> >
> > Java code PigClass.java
> >
> > class PigClass extends EvalFunc<Tuple>
> > {
> > public PigClass(String strPath)
> > {
> > }
> > public Tuple exec(Tuple input ) throws IOException {
> > }
> > };
> >
> > I am getting following Error.
> >
> > *<file MyScript.pig, line 7, column 45> Failed to generate logical plan.
> > Nested exception: java.lang.RuntimeException: could not instantiate '
> > myjar.PigClass**' with arguments '[/home/myfile.txt]'*
> >
> >
> > Thanks and Regards
> > Anil Barfa
> >
>
Re: Passing parameter to UDF
Posted by Prashant Kommireddi <pr...@gmail.com>.
What version of Pig are you using? Can you make sure the package name/path
"myjar.PigClass" is correct.
On Sun, Nov 27, 2011 at 11:56 PM, Anil Barfa <ba...@gmail.com> wrote:
> Hi
> I am using java UDF with pig. I want pass file name to UDF. I have done it
> as follows but it is not working.
>
> PIg script
>
> REGISTER myjar.jar;
> DEFINE myfun myjar.PigClass('/home/myfile.txt');
>
> --load input data
> InputValue = LOAD '$input' AS (val1,val2,val3);
>
> InputWithMeta = FOREACH InputValue GENERATE myfun(val1,val2,val3);
>
>
> Java code PigClass.java
>
> class PigClass extends EvalFunc<Tuple>
> {
> public PigClass(String strPath)
> {
> }
> public Tuple exec(Tuple input ) throws IOException {
> }
> };
>
> I am getting following Error.
>
> *<file MyScript.pig, line 7, column 45> Failed to generate logical plan.
> Nested exception: java.lang.RuntimeException: could not instantiate '
> myjar.PigClass**' with arguments '[/home/myfile.txt]'*
>
>
> Thanks and Regards
> Anil Barfa
>