pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1566519 - in /pig/branches/branch-0.12: src/org/apache/pig/parser/ test/org/apache/pig/test/
Date Mon, 10 Feb 2014 06:38:05 GMT
Author: daijy
Date: Mon Feb 10 06:38:04 2014
New Revision: 1566519

URL: http://svn.apache.org/r1566519
Log:
PIG-3670: Fix assert in Pig script

Modified:
    pig/branches/branch-0.12/src/org/apache/pig/parser/AliasMasker.g
    pig/branches/branch-0.12/src/org/apache/pig/parser/AstPrinter.g
    pig/branches/branch-0.12/src/org/apache/pig/parser/AstValidator.g
    pig/branches/branch-0.12/src/org/apache/pig/parser/LogicalPlanGenerator.g
    pig/branches/branch-0.12/src/org/apache/pig/parser/QueryParser.g
    pig/branches/branch-0.12/test/org/apache/pig/test/TestAssert.java

Modified: pig/branches/branch-0.12/src/org/apache/pig/parser/AliasMasker.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.12/src/org/apache/pig/parser/AliasMasker.g?rev=1566519&r1=1566518&r2=1566519&view=diff
==============================================================================
--- pig/branches/branch-0.12/src/org/apache/pig/parser/AliasMasker.g (original)
+++ pig/branches/branch-0.12/src/org/apache/pig/parser/AliasMasker.g Mon Feb 10 06:38:04 2014
@@ -85,11 +85,15 @@ query : ^( QUERY statement* )
 statement : general_statement
           | split_statement
           | realias_statement
+          | assert_statement
 ;
 
 split_statement : split_clause
 ;
 
+assert_statement: assert_clause
+;
+
 realias_statement : realias_clause
 ;
 
@@ -132,6 +136,7 @@ op_clause : define_clause
           | split_clause
           | foreach_clause
           | cube_clause
+          | assert_clause
 ;
 
 define_clause
@@ -299,6 +304,13 @@ store_clause
     : ^( STORE alias filename func_clause? )
 ;
 
+assert_clause
+    : ^( ASSERT alias cond comment? )
+;
+
+comment : QUOTEDSTRING
+;
+
 filter_clause
     : ^( FILTER rel cond )
 ;
@@ -695,6 +707,7 @@ eid : rel_str_op
     | TOBAG
     | TOMAP
     | TOTUPLE
+    | ASSERT
 ;
 
 // relational operator

Modified: pig/branches/branch-0.12/src/org/apache/pig/parser/AstPrinter.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.12/src/org/apache/pig/parser/AstPrinter.g?rev=1566519&r1=1566518&r2=1566519&view=diff
==============================================================================
--- pig/branches/branch-0.12/src/org/apache/pig/parser/AstPrinter.g (original)
+++ pig/branches/branch-0.12/src/org/apache/pig/parser/AstPrinter.g Mon Feb 10 06:38:04 2014
@@ -57,6 +57,7 @@ statement : general_statement
           | split_statement { sb.append(";\n"); }
           | import_statement { sb.append(";\n"); }
           | register_statement { sb.append(";\n"); }
+          | assert_statement { sb.append(";\n"); }
           | realias_statement
 ;
 
@@ -76,6 +77,9 @@ register_statement : ^( REGISTER QUOTEDS
                         } scripting_udf_clause? )
 ;
 
+assert_statement : assert_clause
+;
+
 scripting_udf_clause : scripting_language_clause scripting_namespace_clause
 ;
 
@@ -735,6 +739,7 @@ eid : rel_str_op
     | TOTUPLE    { sb.append($TOTUPLE.text); }
     | IN         { sb.append($IN.text); }
     | CASE       { sb.append($CASE.text); }
+    | ASSERT     { sb.append($ASSERT.text); }
 ;
 
 // relational operator

Modified: pig/branches/branch-0.12/src/org/apache/pig/parser/AstValidator.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.12/src/org/apache/pig/parser/AstValidator.g?rev=1566519&r1=1566518&r2=1566519&view=diff
==============================================================================
--- pig/branches/branch-0.12/src/org/apache/pig/parser/AstValidator.g (original)
+++ pig/branches/branch-0.12/src/org/apache/pig/parser/AstValidator.g Mon Feb 10 06:38:04
2014
@@ -117,6 +117,7 @@ statement : general_statement
           | split_statement
           | realias_statement
           | register_statement
+          | assert_statement
 ;
 
 split_statement : split_clause
@@ -128,6 +129,9 @@ realias_statement : realias_clause
 register_statement : ^( REGISTER QUOTEDSTRING (USING IDENTIFIER AS IDENTIFIER)? )
 ;
 
+assert_statement : assert_clause
+;
+
 general_statement : ^( STATEMENT ( alias { aliases.add( $alias.name ); } )? op_clause parallel_clause?
)
 ;
 
@@ -724,6 +728,7 @@ eid : rel_str_op
     | TOBAG
     | TOMAP
     | TOTUPLE
+    | ASSERT
 ;
 
 // relational operator

Modified: pig/branches/branch-0.12/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.12/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1566519&r1=1566518&r2=1566519&view=diff
==============================================================================
--- pig/branches/branch-0.12/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/branches/branch-0.12/src/org/apache/pig/parser/LogicalPlanGenerator.g Mon Feb 10 06:38:04
2014
@@ -173,6 +173,7 @@ scope {
  : general_statement
  | split_statement
  | realias_statement
+ | assert_statement
  | register_statement
 ;
 
@@ -182,6 +183,9 @@ split_statement : split_clause
 realias_statement : realias_clause
 ;
 
+assert_statement : assert_clause
+;
+
 register_statement
 : ^( REGISTER QUOTEDSTRING (USING IDENTIFIER AS IDENTIFIER)? )
   {
@@ -1997,6 +2001,7 @@ eid returns[String id] : rel_str_op { $i
     | TOBAG { $id = "TOBAG"; }
     | TOMAP { $id = "TOMAP"; }
     | TOTUPLE { $id = "TOTUPLE"; }
+    | ASSERT { $id = "ASSERT"; } 
 ;
 
 // relational operator

Modified: pig/branches/branch-0.12/src/org/apache/pig/parser/QueryParser.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.12/src/org/apache/pig/parser/QueryParser.g?rev=1566519&r1=1566518&r2=1566519&view=diff
==============================================================================
--- pig/branches/branch-0.12/src/org/apache/pig/parser/QueryParser.g (original)
+++ pig/branches/branch-0.12/src/org/apache/pig/parser/QueryParser.g Mon Feb 10 06:38:04 2014
@@ -224,6 +224,7 @@ statement : SEMI_COLON!
           | import_clause SEMI_COLON!
           | realias_clause SEMI_COLON!
           | register_clause SEMI_COLON!
+          | assert_clause SEMI_COLON!
           // semicolons after foreach_complex_statement are optional for backwards compatibility,
but to keep
           // the grammar unambiguous if there is one then we'll parse it as a single, standalone
semicolon
           // (which matches the first statement rule)
@@ -382,7 +383,6 @@ op_clause : define_clause
           | union_clause
           | stream_clause
           | mr_clause
-          | assert_clause
 ;
 
 ship_clause : SHIP^ LEFT_PAREN! path_list? RIGHT_PAREN!
@@ -1029,6 +1029,7 @@ eid_without_columns : rel_str_op
     | FULL
     | REALIAS
     | BOOL_COND
+    | ASSERT
 ;
 
 eid : eid_without_columns
@@ -1075,6 +1076,5 @@ reserved_identifier_whitelist : RANK
                               | THEN
                               | ELSE
                               | END
-                              | ASSERT
 ;
 

Modified: pig/branches/branch-0.12/test/org/apache/pig/test/TestAssert.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.12/test/org/apache/pig/test/TestAssert.java?rev=1566519&r1=1566518&r2=1566519&view=diff
==============================================================================
--- pig/branches/branch-0.12/test/org/apache/pig/test/TestAssert.java (original)
+++ pig/branches/branch-0.12/test/org/apache/pig/test/TestAssert.java Mon Feb 10 06:38:04
2014
@@ -122,4 +122,29 @@ public class TestAssert {
       }
        
   }
+
+  /**
+   * Verify that alias is not assignable to the ASSERT operator
+   * @throws Exception
+   */
+  @Test(expected=FrontendException.class)
+  public void testNegativeWithAlias() throws Exception {
+      PigServer pigServer = new PigServer(ExecType.LOCAL);
+      Data data = resetData(pigServer);
+
+      data.set("foo",
+              tuple(1),
+              tuple(2),
+              tuple(3)
+              );
+      try {
+          pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (i:int);");
+          pigServer.registerQuery("B = ASSERT A BY i > 1 , 'i should be greater than 1';");
+      }
+      catch (FrontendException fe) {
+          Util.checkMessageInException(fe, "Syntax error, unexpected symbol at or near 'B'");
+          throw fe;
+      }
+  }
+
 }



Mime
View raw message