You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by xu...@apache.org on 2011/04/08 18:26:20 UTC

svn commit: r1090328 - in /pig/trunk: ./ src/org/apache/pig/parser/ test/org/apache/pig/parser/

Author: xuefu
Date: Fri Apr  8 16:26:19 2011
New Revision: 1090328

URL: http://svn.apache.org/viewvc?rev=1090328&view=rev
Log:
PIG-1961: Pig prints null as file name in case of grammar error

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/parser/AstValidator.g
    pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
    pig/trunk/src/org/apache/pig/parser/QueryParser.g
    pig/trunk/src/org/apache/pig/parser/QueryParserUtils.java
    pig/trunk/src/org/apache/pig/parser/SourceLocation.java
    pig/trunk/test/org/apache/pig/parser/TestErrorHandling.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1090328&r1=1090327&r2=1090328&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Fri Apr  8 16:26:19 2011
@@ -26,6 +26,8 @@ PIG-1680: HBaseStorage should work with 
 
 IMPROVEMENTS
 
+PIG-1961: Pig prints "null" as file name in case of grammar error (xuefu)
+
 PIG-1956: Pig parser shouldn't log error code 0 (xuefu)
 
 PIG-1957: Pig parser gives misleading error message when the next foreach block has syntactic errors (xuefu)

Modified: pig/trunk/src/org/apache/pig/parser/AstValidator.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/AstValidator.g?rev=1090328&r1=1090327&r2=1090328&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/AstValidator.g (original)
+++ pig/trunk/src/org/apache/pig/parser/AstValidator.g Fri Apr  8 16:26:19 2011
@@ -58,24 +58,6 @@ throws RecognitionException {
     throw e;
 }
 
-public String getErrorMessage(RecognitionException e, String[] tokenNames) {
-    String msg = e.getMessage();
-    if ( e instanceof DuplicatedSchemaAliasException ) {
-        DuplicatedSchemaAliasException dae = (DuplicatedSchemaAliasException)e;
-        msg = "Duplicated schema alias name '"+ dae.getAlias() + "' in the schema definition";
-    } else if( e instanceof UndefinedAliasException ) {
-        UndefinedAliasException dae = (UndefinedAliasException)e;
-        msg = "Alias '"+ dae.getAlias() + "' is not defined";
-    }
-    
-    return msg;
-}
-
-@Override
-public String getErrorHeader(RecognitionException ex) {
-	return QueryParserUtils.generateErrorHeader( ex );
-}
-
 private void validateSchemaAliasName(Set<String> fieldNames, CommonTree node, String name)
 throws DuplicatedSchemaAliasException {
     if( fieldNames.contains( name ) ) {

Modified: pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1090328&r1=1090327&r2=1090328&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g Fri Apr  8 16:26:19 2011
@@ -134,25 +134,6 @@ public LogicalPlanGenerator(TreeNodeStre
     builder = new LogicalPlanBuilder( pigContext, scope, fileNameMap, input );
 }
 
-public String getErrorMessage(RecognitionException e, String[] tokenNames) {
-    String msg = e.getMessage();
-    if ( e instanceof NonProjectExpressionException ) {
-        NonProjectExpressionException pee = (NonProjectExpressionException)e;
-        msg = "For input to a nested operator, if it's an expression, it can only be " +
-              "a projection expression. The given expression is: " + 
-              pee.getExpression().getPlan() + ".";
-    } else {
-        msg = e.toString();
-    }
-    
-    return msg;
-}
-
-@Override
-public String getErrorHeader(RecognitionException ex) {
-    return QueryParserUtils.generateErrorHeader( ex );
-}
-
 } // End of @members
 
 @rulecatch {

Modified: pig/trunk/src/org/apache/pig/parser/QueryParser.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/QueryParser.g?rev=1090328&r1=1090327&r2=1090328&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/QueryParser.g (original)
+++ pig/trunk/src/org/apache/pig/parser/QueryParser.g Fri Apr  8 16:26:19 2011
@@ -96,6 +96,7 @@ throws RecognitionException {
     throw e;
 }
 
+@Override
 public String getErrorMessage(RecognitionException e, String[] tokenNames ) {
     if( !log.isDebugEnabled() ) {
         if( e instanceof NoViableAltException ) {
@@ -117,6 +118,7 @@ public String getErrorMessage(Recognitio
     return stack + " " + msg;
 }
 
+@Override
 public String getTokenErrorDisplay(Token t) {
     return "'" + t.getText() + "'";
 }

Modified: pig/trunk/src/org/apache/pig/parser/QueryParserUtils.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/QueryParserUtils.java?rev=1090328&r1=1090327&r2=1090328&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/QueryParserUtils.java (original)
+++ pig/trunk/src/org/apache/pig/parser/QueryParserUtils.java Fri Apr  8 16:26:19 2011
@@ -170,16 +170,8 @@ public class QueryParserUtils {
          return alias + "_" + filename + "_" + funcSpec.toString();
      }
      
-     static String generateErrorHeader(RecognitionException ex) {
-         return "<line " + ex.line +", column " + ex.charPositionInLine + ">";
-     }
-
-    static String generateErrorHeader(RecognitionException ex, String fname) {
-        StringBuilder sb = new StringBuilder();
-        sb.append("<file ").append(fname).append(", line ")
-                .append(ex.line).append(", column ")
-                .append(ex.charPositionInLine).append(">");
-        return sb.toString();
+    static String generateErrorHeader(RecognitionException ex, String filename) {
+        return new SourceLocation( filename, ex.line, ex.charPositionInLine ).toString();
     }
     
     @SuppressWarnings({ "unchecked", "rawtypes" })

Modified: pig/trunk/src/org/apache/pig/parser/SourceLocation.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/SourceLocation.java?rev=1090328&r1=1090327&r2=1090328&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/SourceLocation.java (original)
+++ pig/trunk/src/org/apache/pig/parser/SourceLocation.java Fri Apr  8 16:26:19 2011
@@ -26,6 +26,12 @@ public class SourceLocation {
     public SourceLocation() {
     }
     
+    public SourceLocation(String filename, int line, int offset) {
+    	this.file = filename;
+    	this.line = line;
+    	this.offset = offset;
+    }
+    
     public SourceLocation(PigParserNode tree) {
         this.file = tree.getFileName();
         this.line = tree.getLine();

Modified: pig/trunk/test/org/apache/pig/parser/TestErrorHandling.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/parser/TestErrorHandling.java?rev=1090328&r1=1090327&r2=1090328&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/parser/TestErrorHandling.java (original)
+++ pig/trunk/test/org/apache/pig/parser/TestErrorHandling.java Fri Apr  8 16:26:19 2011
@@ -173,4 +173,34 @@ public class TestErrorHandling {
         Assert.fail( "Testcase should fail" );
     }
 
+    @Test // PIG-1961
+    public void tesNegative11() throws IOException {
+        String query = "A = load ^ 'x' as (name, age, gpa);\n";
+        try {
+            pig.registerQuery( query );
+        } catch(FrontendException ex) {
+        	String msg = ex.getMessage();
+            System.out.println( msg );
+            Assert.assertFalse( msg.contains( "file null" ) );
+            Assert.assertTrue( msg.contains( "Unexpected character" ) );
+            return;
+        }
+        Assert.fail( "Testcase should fail" );
+    }
+    
+    @Test // PIG-1961
+    public void tesNegative12() throws IOException {
+        String query = "A = loadd 'x' as (name, age, gpa);\n";
+        try {
+            pig.registerQuery( query );
+        } catch(FrontendException ex) {
+        	String msg = ex.getMessage();
+            System.out.println( msg );
+            Assert.assertFalse( msg.contains( "file null" ) );
+            Assert.assertTrue( msg.contains( "mismatched input ''x'' expecting LEFT_PAREN" ) );
+            return;
+        }
+        Assert.fail( "Testcase should fail" );
+    }
+
 }