You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by th...@apache.org on 2011/05/16 20:41:32 UTC

svn commit: r1103827 - in /pig/trunk: CHANGES.txt src/org/apache/pig/newplan/logical/visitor/TypeCheckingRelVisitor.java test/org/apache/pig/test/TestLogicalPlanBuilder.java test/org/apache/pig/test/TestTypeCheckingValidatorNewLP.java

Author: thejas
Date: Mon May 16 18:41:31 2011
New Revision: 1103827

URL: http://svn.apache.org/viewvc?rev=1103827&view=rev
Log:
PIG-2070: "Unknown" appears in error message for an error case

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/newplan/logical/visitor/TypeCheckingRelVisitor.java
    pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java
    pig/trunk/test/org/apache/pig/test/TestTypeCheckingValidatorNewLP.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1103827&r1=1103826&r2=1103827&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Mon May 16 18:41:31 2011
@@ -224,6 +224,8 @@ PIG-1696: Performance: Use System.arrayc
 
 BUG FIXES
 
+PIG-2070: "Unknown" appears in error message for an error case (thejas)
+
 PIG-2069: LoadFunc jar does not ship to backend in MultiQuery case (rding)
 
 PIG-2076: update documentation, help command with correct default value 

Modified: pig/trunk/src/org/apache/pig/newplan/logical/visitor/TypeCheckingRelVisitor.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/visitor/TypeCheckingRelVisitor.java?rev=1103827&r1=1103826&r2=1103827&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/visitor/TypeCheckingRelVisitor.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/visitor/TypeCheckingRelVisitor.java Mon May 16 18:41:31 2011
@@ -134,13 +134,12 @@ public class TypeCheckingRelVisitor exte
     }
     
     private void throwTypeCheckerException(Operator op, String msg,
-			int errCode, byte input, FrontendException fe) throws TypeCheckerException {
-    	if( fe == null ) {
-		    throw new TypeCheckerException(op, msg, errCode, PigException.INPUT);
-    	}
-		throw new TypeCheckerException(op, msg, errCode, PigException.INPUT, fe);
-		
-	}
+            int errCode, byte input, FrontendException fe) throws TypeCheckerException {
+        if( fe == null ) {
+            throw new TypeCheckerException(op, msg, errCode, PigException.INPUT);
+        }
+        throw new TypeCheckerException(op, msg, errCode, PigException.INPUT, fe);
+    }
 
 	@Override
     public void visit(LOGenerate gen) throws FrontendException {
@@ -614,7 +613,7 @@ public class TypeCheckingRelVisitor exte
             }
             else {
                 //schema of the group-by key
-                LogicalSchema groupBySchema = getSchemaFromInnerPlans(join.getExpressionPlans()) ;
+                LogicalSchema groupBySchema = getSchemaFromInnerPlans(join.getExpressionPlans(), join) ;
 
                 // go through all inputs again to add cast if necessary
                 for(int i=0;i < inputs.size(); i++) {
@@ -811,7 +810,11 @@ public class TypeCheckingRelVisitor exte
      * @return
      * @throws FrontendException
      */
-    private LogicalSchema getSchemaFromInnerPlans(MultiMap<Integer, LogicalExpressionPlan> exprPlans) throws FrontendException {
+    private LogicalSchema getSchemaFromInnerPlans(
+            MultiMap<Integer, LogicalExpressionPlan> exprPlans,
+            LogicalRelationalOperator op
+    )
+    throws FrontendException {
         // this fsList represents all the columns in group tuple
         List<LogicalFieldSchema> fsList = new ArrayList<LogicalFieldSchema>() ;
 
@@ -840,7 +843,7 @@ public class TypeCheckingRelVisitor exte
                         int errCode = 1013;
                         String msg = "Grouping attributes can either be star (*) " +
                         "or a list of expressions, but not both.";
-
+                        msgCollector.collect(msg, MessageType.Error) ;
                         throw new FrontendException(
                                 msg, errCode, PigException.INPUT, false, null
                         );         
@@ -849,6 +852,23 @@ public class TypeCheckingRelVisitor exte
                 //merge the type
                 LogicalFieldSchema groupFs = fsList.get(j);
                 groupFs.type = DataType.mergeType(groupFs.type, innerType) ;
+                if(groupFs.type == DataType.ERROR){
+                    String colType = "join";
+                    if(op instanceof LOCogroup){
+                        colType = "group";
+                    }
+                    String msg =
+                        colType + " column no. " +
+                        (j+1) + " in relation no. " + (i+1) + " of  " + colType + 
+                        " statement has datatype " + DataType.findTypeName(innerType) +
+                        " which is incompatible with type of corresponding column" +
+                        " in earlier relation(s) in the statement";
+                    msgCollector.collect(msg, MessageType.Error) ;
+                    TypeCheckerException ex =
+                        new TypeCheckerException(op, msg, 1130, PigException.INPUT);
+                    ex.setMarkedAsShowToUser(true);
+                    throw ex;
+                }
             }
 
         }
@@ -927,7 +947,7 @@ public class TypeCheckingRelVisitor exte
             }
             else {
 
-                LogicalSchema groupBySchema = getSchemaFromInnerPlans(cg.getExpressionPlans());
+                LogicalSchema groupBySchema = getSchemaFromInnerPlans(cg.getExpressionPlans(), cg);
 
                 // go through all inputs again to add cast if necessary
                 for(int i=0;i < inputs.size(); i++) {

Modified: pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=1103827&r1=1103826&r2=1103827&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java Mon May 16 18:41:31 2011
@@ -2054,7 +2054,11 @@ public class TestLogicalPlanBuilder {
             "store c into 'output';";
             buildPlan( query );
         } catch (AssertionFailedError e) {
-            Assert.assertTrue(e.getMessage().contains("Cannot cast to Unknown"));
+            String msg =
+                "group column no. 2 in relation no. 2 of  group statement" +
+                " has datatype chararray which is incompatible with type of" +
+                " corresponding column in earlier relation(s) in the statement";
+            Assert.assertTrue(e.getMessage().contains(msg));
             exceptionThrown = true;
         }
         Assert.assertEquals("An exception was expected but did " +

Modified: pig/trunk/test/org/apache/pig/test/TestTypeCheckingValidatorNewLP.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestTypeCheckingValidatorNewLP.java?rev=1103827&r1=1103826&r2=1103827&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestTypeCheckingValidatorNewLP.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestTypeCheckingValidatorNewLP.java Mon May 16 18:41:31 2011
@@ -4144,5 +4144,18 @@ public class TestTypeCheckingValidatorNe
                 fail("caught exception creating lp");
             }
         }
+        
+        @Test //PIG-2070
+        public void testJoinIncompatType() throws IOException{
+            String query = "a = load '1.txt' as (a0:map [], a1:int);" +
+                "b = load '2.txt' as (a0:int, a1:int);" +
+                "c = join a by (a0, a1), b by (a0,a1);";
+            String msg =
+                "join column no. 1 in relation no. 2 of  join statement" +
+                " has datatype int which is incompatible with type of" +
+                " corresponding column in earlier relation(s) in the statement";
+            Util.checkExceptionMessage(query, "c", msg);
+
+        }
 
 }