pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1566075 - in /pig/trunk: CHANGES.txt src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj test/org/apache/pig/test/TestAssert.java
Date Sat, 08 Feb 2014 18:14:48 GMT
Author: daijy
Date: Sat Feb  8 18:14:48 2014
New Revision: 1566075

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

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
    pig/trunk/test/org/apache/pig/test/TestAssert.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1566075&r1=1566074&r2=1566075&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Sat Feb  8 18:14:48 2014
@@ -87,6 +87,8 @@ OPTIMIZATIONS
  
 BUG FIXES
 
+PIG-3670: Fix assert in Pig script (daijy)
+
 PIG-3447: Compiler warning message dropped for CastLineageSetter and others with no enum
kind (knoguchi via cheolsoo)
 
 PIG-3627: Json storage : Doesn't work in cases , where other Store Functions (like PigStorage
/ AvroStorage)

Modified: pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj?rev=1566075&r1=1566074&r2=1566075&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj (original)
+++ pig/trunk/src/org/apache/pig/tools/pigscript/parser/PigScriptParser.jj Sat Feb  8 18:14:48
2014
@@ -247,11 +247,12 @@ TOKEN_MGR_DECLS : {
 {
     <"split"> : PIG_START
 |   <"define"> : PIG_START
-|	<"store"> : PIG_START
-|	<"import"> : PIG_START
-| 	<(["a"-"z", "A"-"Z"])+(["a"-"z", "A"-"Z"] | ["0"-"9"] | "_")*(" " | "\t")*"="> :
PIG_START
+|   <"store"> : PIG_START
+|   <"assert"> : PIG_START
+|   <"import"> : PIG_START
+|   <(["a"-"z", "A"-"Z"])+(["a"-"z", "A"-"Z"] | ["0"-"9"] | "_")*(" " | "\t")*"=">
: PIG_START
 |   <"=>" (" " | "\t")*> : PIG_START
-| 	< <IDENTIFIER> (" " | "\t")* ("," (" " | "\t")* <IDENTIFIER> )* (" " |
"\t")* "="> : PIG_START
+|   < <IDENTIFIER> (" " | "\t")* ("," (" " | "\t")* <IDENTIFIER> )* (" " |
"\t")* "="> : PIG_START
 |   < <IDENTIFIER> (" " | "\t")* "(" > : PIG_START
 }
 

Modified: pig/trunk/test/org/apache/pig/test/TestAssert.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestAssert.java?rev=1566075&r1=1566074&r2=1566075&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestAssert.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestAssert.java Sat Feb  8 18:14:48 2014
@@ -21,6 +21,8 @@ import static junit.framework.Assert.ass
 import static org.apache.pig.builtin.mock.Storage.resetData;
 import static org.apache.pig.builtin.mock.Storage.tuple;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.util.List;
 import java.util.Properties;
 
@@ -55,7 +57,7 @@ public class TestAssert {
       pigServer.registerQuery("A = LOAD 'foo' USING mock.Storage() AS (i:int);");
       pigServer.registerQuery("ASSERT A BY i > 0;");
       pigServer.registerQuery("STORE A INTO 'bar' USING mock.Storage();");
-      
+
       pigServer.executeBatch();
 
       List<Tuple> out = data.get("bar");
@@ -64,7 +66,38 @@ public class TestAssert {
       assertEquals(tuple(2), out.get(1));
       assertEquals(tuple(3), out.get(2));
   }
-  
+
+  /**
+   * Verify that ASSERT operator works in a Pig script
+   * See PIG-3670
+   * @throws Exception
+   */
+  @Test
+  public void testInScript() throws Exception {
+      PigServer pigServer = new PigServer(ExecType.LOCAL);
+      Data data = resetData(pigServer);
+
+      data.set("foo",
+              tuple(1),
+              tuple(2),
+              tuple(3)
+              );
+
+      StringBuffer query = new StringBuffer();
+      query.append("A = LOAD 'foo' USING mock.Storage() AS (i:int);\n");
+      query.append("ASSERT A BY i > 0;\n");
+      query.append("STORE A INTO 'bar' USING mock.Storage();");
+
+      InputStream is = new ByteArrayInputStream(query.toString().getBytes());
+      pigServer.registerScript(is);
+
+      List<Tuple> out = data.get("bar");
+      assertEquals(3, out.size());
+      assertEquals(tuple(1), out.get(0));
+      assertEquals(tuple(2), out.get(1));
+      assertEquals(tuple(3), out.get(2));
+  }
+
   /**
    * Verify that ASSERT operator works
    * @throws Exception



Mime
View raw message