You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by rd...@apache.org on 2011/01/18 19:16:48 UTC

svn commit: r1060502 - in /pig/trunk: CHANGES.txt src/org/apache/pig/scripting/Pig.java src/org/apache/pig/scripting/ScriptEngine.java src/org/apache/pig/scripting/jython/JythonScriptEngine.java test/org/apache/pig/test/TestScriptLanguage.java

Author: rding
Date: Tue Jan 18 18:16:48 2011
New Revision: 1060502

URL: http://svn.apache.org/viewvc?rev=1060502&view=rev
Log:
PIG-1801: Need better error message for Jython errors

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/scripting/Pig.java
    pig/trunk/src/org/apache/pig/scripting/ScriptEngine.java
    pig/trunk/src/org/apache/pig/scripting/jython/JythonScriptEngine.java
    pig/trunk/test/org/apache/pig/test/TestScriptLanguage.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1060502&r1=1060501&r2=1060502&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue Jan 18 18:16:48 2011
@@ -75,6 +75,8 @@ PIG-1696: Performance: Use System.arrayc
 
 BUG FIXES
 
+PIG-1801: Need better error message for Jython errors (rding)
+
 PIG-1742: org.apache.pig.newplan.optimizer.Rule.java does not work
   with plan patterns where leaves/sinks are not siblings (thejas)
 

Modified: pig/trunk/src/org/apache/pig/scripting/Pig.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/scripting/Pig.java?rev=1060502&r1=1060501&r2=1060502&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/scripting/Pig.java (original)
+++ pig/trunk/src/org/apache/pig/scripting/Pig.java Tue Jan 18 18:16:48 2011
@@ -58,7 +58,8 @@ public class Pig {
         FsShell shell = new FsShell(ConfigurationUtil.toConfiguration(ctx
                 .getPigContext().getProperties()));
         if (cmd != null) {
-            String[] cmdTokens = cmd.split("\\s+");            
+            String[] cmdTokens = cmd.split("\\s+");         
+            if (!cmdTokens[0].startsWith("-")) cmdTokens[0] = "-" + cmdTokens[0];
             try {
                 shell.run(cmdTokens);
             } catch (Exception e) {

Modified: pig/trunk/src/org/apache/pig/scripting/ScriptEngine.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/scripting/ScriptEngine.java?rev=1060502&r1=1060501&r2=1060502&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/scripting/ScriptEngine.java (original)
+++ pig/trunk/src/org/apache/pig/scripting/ScriptEngine.java Tue Jan 18 18:16:48 2011
@@ -78,7 +78,7 @@ public abstract class ScriptEngine {
      * Loads the script in the interpreter.
      * @param script
      */
-    protected abstract void load(InputStream script);
+    protected abstract void load(InputStream script) throws IOException;
 
     /**
      * Gets ScriptEngine classname or keyword for the scripting language

Modified: pig/trunk/src/org/apache/pig/scripting/jython/JythonScriptEngine.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/scripting/jython/JythonScriptEngine.java?rev=1060502&r1=1060501&r2=1060502&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/scripting/jython/JythonScriptEngine.java (original)
+++ pig/trunk/src/org/apache/pig/scripting/jython/JythonScriptEngine.java Tue Jan 18 18:16:48 2011
@@ -34,12 +34,14 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pig.FuncSpec;
 import org.apache.pig.PigServer;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.impl.PigContext;
 import org.apache.pig.impl.logicalLayer.parser.ParseException;
 import org.apache.pig.impl.util.Utils;
 import org.apache.pig.scripting.ScriptEngine;
 import org.apache.pig.tools.pigstats.PigStats;
 import org.python.core.Py;
+import org.python.core.PyException;
 import org.python.core.PyFrame;
 import org.python.core.PyFunction;
 import org.python.core.PyObject;
@@ -101,7 +103,7 @@ public class JythonScriptEngine extends 
                     }
                                         
                     if (is != null) {
-                        interpreter.execfile(is); 
+                        execfile(is); 
                         filesLoaded.add(path);
                     } else {
                         throw new IOException(
@@ -113,8 +115,13 @@ public class JythonScriptEngine extends 
             }           
         }        
         
-        static void execfile(InputStream script) {
-            interpreter.execfile(script);
+        static void execfile(InputStream script) throws ExecException {
+            try {
+                interpreter.execfile(script);
+            } catch (PyException e) {
+                String message = "Python Error. "+e.toString();
+                throw new ExecException(message, 1121, e);
+            }
         }
         
         static String get(String name) {
@@ -215,7 +222,7 @@ public class JythonScriptEngine extends 
     }
    
     @Override
-    public void load(InputStream script) {
+    public void load(InputStream script) throws IOException {
         Interpreter.execfile(script);
     }
 

Modified: pig/trunk/test/org/apache/pig/test/TestScriptLanguage.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestScriptLanguage.java?rev=1060502&r1=1060501&r2=1060502&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestScriptLanguage.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestScriptLanguage.java Tue Jan 18 18:16:48 2011
@@ -18,6 +18,7 @@
 package org.apache.pig.test;
 
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -66,7 +67,7 @@ public class TestScriptLanguage {
         String[] script = {
                 "#!/usr/bin/python",
                 "from org.apache.pig.scripting import *",
-                "Pig.fs(\"-rmr simple_out\")",
+                "Pig.fs(\"rmr simple_out\")",
                 "input = 'simple_table'",
                 "output = 'simple_out'",
                 "P = Pig.compile(\"\"\"a = load '$input';store a into '$output';\"\"\")",
@@ -104,7 +105,7 @@ public class TestScriptLanguage {
         String[] script = {
                 "#!/usr/bin/python",
                 "from org.apache.pig.scripting import *",
-                "Pig.fs(\"-rmr simple_out\")",
+                "Pig.fs(\"rmr simple_out\")",
                 "input = 'simple_table_6'",
                 "output = 'simple_out'",
                 "P = Pig.compileFromFile(\"\"\"testScript.pig\"\"\")",
@@ -148,8 +149,8 @@ public class TestScriptLanguage {
         String[] script = {
                 "#!/usr/bin/python",
                 "from org.apache.pig.scripting import *",
-                "Pig.fs(\"-rmr simple_out\")",
-                "Pig.fs(\"-rmr simple_out2\")",
+                "Pig.fs(\"rmr simple_out\")",
+                "Pig.fs(\"rmr simple_out2\")",
                 "input = 'simple_table_1'",
                 "output1 = 'simple_out'",
                 "output2 = 'simple_out'",
@@ -184,7 +185,7 @@ public class TestScriptLanguage {
     public void pigRunnerTest() throws Exception {
         String[] script = {
                 "from org.apache.pig.scripting import *",
-                "Pig.fs(\"-rmr simple_out\")",
+                "Pig.fs(\"rmr simple_out\")",
                 "input = 'simple_table_2'",
                 "output = 'simple_out'",
                 "P = Pig.compile(\"\"\"a = load '$input';store a into '$output';\"\"\")",
@@ -227,8 +228,8 @@ public class TestScriptLanguage {
                 "#!/usr/bin/python",
                 "from org.apache.pig.scripting import *",
                 "input = 'simple_table_3'",
-                "Pig.fs(\"-rmr simple_out\")",
-                "Pig.fs(\"-rmr simple_out2\")",
+                "Pig.fs(\"rmr simple_out\")",
+                "Pig.fs(\"rmr simple_out2\")",
                 "output1 = 'simple_out'",
                 "output2 = 'simple_out2'",
                 "P = Pig.compile(\"mypipeline\", \"\"\"a = load '$input';store a into '$output';\"\"\")",
@@ -266,8 +267,8 @@ public class TestScriptLanguage {
         String[] script = {
                 "#!/usr/bin/python",
                 "from org.apache.pig.scripting import *",
-                "Pig.fs(\"-rmr simple_out\")",
-                "Pig.fs(\"-rmr simple_out2\")",
+                "Pig.fs(\"rmr simple_out\")",
+                "Pig.fs(\"rmr simple_out2\")",
                 "input = 'simple_table_4'",
                 "P = Pig.compile(\"mypipeline\", \"\"\"a = load '$input';store a into '$output';\"\"\")",
                 "for x in [\"simple_out\", \"simple_out2\"]:",
@@ -304,7 +305,7 @@ public class TestScriptLanguage {
         String[] script = {
                 "#!/usr/bin/python",
                 "from org.apache.pig.scripting import *",
-                "Pig.fs(\"-rmr simple_out\")",
+                "Pig.fs(\"rmr simple_out\")",
                 "input = 'simple_table_5'",
                 "output = 'simple_out'",
                 "P = Pig.compile(\"\"\"a = load '$input';store a into '$output';\"\"\")",
@@ -337,4 +338,37 @@ public class TestScriptLanguage {
         assertEquals(3, stats.getRecordWritten());     
     }
 
+    @Test
+    public void NegativeTest() throws Exception {
+        String[] script = {
+                "#!/usr/bin/python",
+                " from org.apache.pig.scripting import *",
+                "Pig.fs(\"rmr simple_out\")"
+        };
+
+        Util.createLocalInputFile( "testScript.py", script);
+        
+        String[] args = { "-x", "local", "testScript.py"};
+        PigStats stats = PigRunner.run(args, null);
+        assertFalse(stats.isSuccessful());
+        assertTrue(stats.getErrorCode() == 1121);
+        assertTrue(stats.getReturnCode() == PigRunner.ReturnCode.PIG_EXCEPTION);        
+    }
+   
+    @Test
+    public void NegativeTest2() throws Exception {
+        String[] script = {
+                "#!/usr/bin/python",
+                " from org.apache.pig.scripting import *",
+                "raise 'This is a test'"
+        };
+
+        Util.createLocalInputFile( "testScript.py", script);
+        
+        String[] args = { "-x", "local", "testScript.py"};
+        PigStats stats = PigRunner.run(args, null);
+        assertFalse(stats.isSuccessful());
+        assertTrue(stats.getErrorCode() == 1121);
+        assertTrue(stats.getReturnCode() == PigRunner.ReturnCode.PIG_EXCEPTION);
+    }
 }