Author: olga
Date: Tue Mar 25 17:06:50 2008
New Revision: 641081

URL: http://svn.apache.org/viewvc?rev=641081&view=rev
Log:
PIG-100: imprived error handling

Added:
    incubator/pig/trunk/src/org/apache/pig/tools/grunt/Utils.java
Modified:
    incubator/pig/trunk/CHANGES.txt
    
incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    incubator/pig/trunk/src/org/apache/pig/tools/grunt/Grunt.java
    incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
    incubator/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java

Modified: incubator/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=641081&r1=641080&r2=641081&view=diff
==============================================================================
--- incubator/pig/trunk/CHANGES.txt (original)
+++ incubator/pig/trunk/CHANGES.txt Tue Mar 25 17:06:50 2008
@@ -179,3 +179,5 @@
        collector tells us we are out of memory (gates).
 
     PIG-154: moving parsing for DEFINE and STORE into QueryParser
+
+    PIG-100: improved error handling

Modified: 
incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=641081&r1=641080&r2=641081&view=diff
==============================================================================
--- 
incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt 
(original)
+++ 
incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt 
Tue Mar 25 17:06:50 2008
@@ -489,6 +489,22 @@
                LogicalOperator aliasOp;
                String alias = t1.image;
                
+               if (aliases == null) {
+                       throw new RuntimeException("aliases var is not 
initialize.");
+               }
+               if (aliases.get(alias) == null) {
+                       StringBuilder msg = new StringBuilder();
+                       msg.append("Unable to find alias: '");
+                       msg.append(alias);
+                       msg.append("' - aliases: '");
+                       for (String tmpAlias : aliases.keySet()) {
+                               msg.append(tmpAlias);
+                               msg.append(",");
+                       }
+                       msg.append("'");
+                       throw new ParseException(msg.toString());
+               }
+               
                aliasOp = opTable.get(aliases.get(alias).getRoot());
                
                if (aliasOp == null) {
@@ -1096,7 +1112,10 @@
                try{
                        EvalFunc ef = (EvalFunc) 
pigContext.instantiateFuncFromAlias(funcName);
                }catch (Exception e){
-                       throw new ParseException(e.getMessage());
+                       //throw new ParseException(e.getMessage());
+            ParseException pe = new ParseException(e.getMessage());
+            pe.initCause(e);
+                       throw pe;
                }
                return funcName;
        }

Modified: incubator/pig/trunk/src/org/apache/pig/tools/grunt/Grunt.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/tools/grunt/Grunt.java?rev=641081&r1=641080&r2=641081&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/tools/grunt/Grunt.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/tools/grunt/Grunt.java Tue Mar 25 
17:06:50 2008
@@ -18,6 +18,8 @@
 package org.apache.pig.tools.grunt;
 
 import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -56,8 +58,16 @@
         try {
         parser.setInteractive(false);
         parser.parseStopOnError();
-        } catch (Throwable e) {
-            log.error(e.getMessage());
+        } catch (Exception e) {
+            Exception pe = Utils.getPermissionException(e);
+            if (pe != null)
+                log.error("You don't have permission to perform the operation. 
Error from the server: " + pe.getMessage());
+            else {
+                ByteArrayOutputStream bs = new ByteArrayOutputStream();
+                e.printStackTrace(new PrintStream(bs));
+                log.error(bs.toString());
+                log.error(e.getMessage());
+           }
     }
     
     }

Modified: incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java?rev=641081&r1=641080&r2=641081&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java 
(original)
+++ incubator/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java Tue Mar 
25 17:06:50 2008
@@ -1,7 +1,9 @@
 package org.apache.pig.tools.grunt;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.io.Reader;
 import java.util.Iterator;
 import java.util.Map;
@@ -11,6 +13,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.mapred.JobClient;
 import org.apache.hadoop.mapred.RunningJob;
+import org.apache.hadoop.fs.permission.AccessControlException;
 import org.apache.pig.PigServer;
 import org.apache.pig.backend.datastorage.ContainerDescriptor;
 import org.apache.pig.backend.datastorage.DataStorage;
@@ -71,7 +74,16 @@
             }
             catch(Exception e)
             {
-                log.error(e.getMessage());
+                Exception pe = Utils.getPermissionException(e);
+                if (pe != null)
+                    log.error("You don't have permission to perform the 
operation. Error from the server: " + pe.getMessage());
+                else
+                {    
+                    ByteArrayOutputStream bs = new ByteArrayOutputStream();
+                    e.printStackTrace(new PrintStream(bs));
+                    log.error(bs.toString());
+                    log.error(e);
+                }
             }
     }
 
@@ -106,7 +118,7 @@
             System.err.flush();
         }
     }
-    
+
     protected void quit()
     {
         mDone = true;

Added: incubator/pig/trunk/src/org/apache/pig/tools/grunt/Utils.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/tools/grunt/Utils.java?rev=641081&view=auto
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/tools/grunt/Utils.java (added)
+++ incubator/pig/trunk/src/org/apache/pig/tools/grunt/Utils.java Tue Mar 25 
17:06:50 2008
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.tools.grunt;
+
+class Utils {
+    static Exception getPermissionException(Exception top){
+        Throwable current = top;
+
+        while (current != null && current.getMessage().indexOf("Permission 
denied") == -1){
+            current = current.getCause();
+        }
+        return (Exception)current;
+    }
+}

Modified: 
incubator/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=641081&r1=641080&r2=641081&view=diff
==============================================================================
--- incubator/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java 
(original)
+++ incubator/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java 
Tue Mar 25 17:06:50 2008
@@ -42,6 +42,7 @@
 import org.apache.pig.impl.logicalLayer.LogicalOperator;
 import org.apache.pig.impl.logicalLayer.LogicalPlan;
 import org.apache.pig.impl.logicalLayer.LogicalPlanBuilder;
+import org.apache.pig.impl.logicalLayer.parser.ParseException;
 
 
 public class TestLogicalPlanBuilder extends junit.framework.TestCase {
@@ -450,6 +451,39 @@
                return;
         }
         assertTrue(false);
+    }
+
+    @Test
+    public void testRegressionPig100NoSuchAlias() throws Throwable {
+        PigContext pigContext = new PigContext(ExecType.LOCAL);
+        LogicalPlanBuilder builder = new LogicalPlanBuilder(pigContext);
+
+        boolean caughtIt = false;
+        try {
+            LogicalPlan lp = builder.parse("test",
+                "b = filter c by $0 > '5';", aliases, logicalOpTable);
+        } catch (ParseException e) {
+            caughtIt = true;
+                       assertEquals("Unable to find alias:",
+                               e.getMessage().substring(0, 21));
+        }
+        assertTrue(caughtIt);
+    }
+
+    @Test
+    public void testRegressionPig100NoAliases() throws Throwable {
+        PigContext pigContext = new PigContext(ExecType.LOCAL);
+        LogicalPlanBuilder builder = new LogicalPlanBuilder(pigContext);
+
+        boolean caughtIt = false;
+        try {
+            LogicalPlan lp = builder.parse("test",
+                               "b = filter c by $0 > '5';", null, 
logicalOpTable);
+        } catch (RuntimeException e) {
+            caughtIt = true;
+                       assertEquals("aliases var is not initialize.", 
e.getMessage());
+        }
+        assertTrue(caughtIt);
     }
 
        /*


Reply via email to