2

I want to run a python function using jython..

Taking the example from this site.

http://sundaycomputing.blogspot.com/2011/01/python-udfs-from-pig-scripts.html

Now when i run the script (pig -f myscript.pig

It returns me this error

     Pig Stack Trace
---------------
ERROR 2998: Unhandled internal error. org/python/core/PyException

java.lang.NoClassDefFoundError: org/python/core/PyException
    at org.apache.pig.scripting.jython.JythonScriptEngine.registerFunctions(JythonScriptEngine.java:127)
    at org.apache.pig.PigServer.registerCode(PigServer.java:567)
    at org.apache.pig.tools.grunt.GruntParser.processRegister(GruntParser.java:421)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:419)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:188)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:164)
    at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:81)
    at org.apache.pig.Main.run(Main.java:427)
    at org.apache.pig.Main.main(Main.java:108)
Caused by: java.lang.ClassNotFoundException: org.python.core.PyException
    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)
    ... 9 more
================================================================================

I am guessing its because of the first line.. REGISTER udf.py USING jython AS udf;

and that I have to specify jython path? (since i am running this code on cluster.. i dont think i have set this thing up).. Now... since i dont know much of java.. hence switched on python ... but how do i make this code run??

What sort of setup i have to do on my env... to debug this problem. Thanks

frazman
  • 32,081
  • 75
  • 184
  • 269
  • 1
    Pig is just a java class. You will need a jython.jar somewhere in your classpath. Try looking through the Pig executable script for where to do this. Alternatively, you can invoke Pig using the pig jar like so: java -cp /path/to/pig-0.##.0.jar:/path/to/jython.jar org.apache.pig.Main – reo katoa Nov 12 '12 at 21:27
  • Similar post: http://stackoverflow.com/questions/9300509/how-do-you-use-python-udfs-with-pig-in-elastic-mapreduce – Lorand Bendig Nov 13 '12 at 08:38

1 Answers1

1

Add $PIG_HOME/lib/jython.jar to your PIG_CLASSPATH environment variable.

Lorand Bendig
  • 10,630
  • 1
  • 38
  • 45