Could any one please provide a sample code of pig with groovy UDF, along
with the process to deplo and run it?
I tried on my own which is not working

I wrote a groovy UDF as

import org.apache.pig.builtin.OutputSchema;

class GroovyUDFs {
  @OutputSchema('x:long')
  long square(long x) {
    return x*x;
  }
}

I have written a simple pig as

--Register 'test.groovy' using groovy as myfuncs;
register 'test.groovy' using
org.apache.pig.scripting.groovy.GroovyScriptEngine as myfuncs;

--A = LOAD 'emp.csv' As(id:int, name:chararray, salary:long);
--B = FOR EACH A myfuncs.GroovyUDFs.square(A.id);
--DUMP A;


Only register command is kept uncommented and ran pig in local mode
I am getting below error

Pig Stack Trace
---------------
ERROR 2998: Unhandled internal error. groovy/util/ResourceException

java.lang.NoClassDefFoundError: groovy/util/ResourceException
 at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.apache.pig.scripting.ScriptEngine.getInstance(ScriptEngine.java:275)
 at org.apache.pig.PigServer.registerCode(PigServer.java:502)
at
org.apache.pig.tools.grunt.GruntParser.processRegister(GruntParser.java:436)
 at
org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:445)
at
org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:194)
 at
org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:170)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
 at org.apache.pig.Main.run(Main.java:604)
at org.apache.pig.Main.main(Main.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.RunJar.main(RunJar.java:208)
Caused by: java.lang.ClassNotFoundException: groovy.util.ResourceException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
 ... 16 more
================================================================================

Reply via email to