You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ch...@apache.org on 2013/06/10 02:31:05 UTC

svn commit: r1491314 - in /pig/trunk: CHANGES.txt src/org/apache/pig/parser/AstPrinter.g test/org/apache/pig/test/TestMacroExpansion.java

Author: cheolsoo
Date: Mon Jun 10 00:31:05 2013
New Revision: 1491314

URL: http://svn.apache.org/r1491314
Log:
PIG-3250: Pig dryrun generates wrong output in .expanded file for 'SPLIT....OTHERWISE...' command (dreambird via cheolsoo)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/parser/AstPrinter.g
    pig/trunk/test/org/apache/pig/test/TestMacroExpansion.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1491314&r1=1491313&r2=1491314&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Mon Jun 10 00:31:05 2013
@@ -196,6 +196,8 @@ PIG-3013: BinInterSedes improve chararra
 
 BUG FIXES
 
+PIG-3250: Pig dryrun generates wrong output in .expanded file for 'SPLIT....OTHERWISE...' command (dreambird via cheolsoo)
+
 PIG-3331: Default values not stored in avro file when using specific schemas during store in AvroStorage (viraj via rohini)
 
 PIG-3322: AvroStorage give NPE on reading file with union as top level schema (viraj via rohini)

Modified: pig/trunk/src/org/apache/pig/parser/AstPrinter.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/AstPrinter.g?rev=1491314&r1=1491313&r2=1491314&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/AstPrinter.g (original)
+++ pig/trunk/src/org/apache/pig/parser/AstPrinter.g Mon Jun 10 00:31:05 2013
@@ -545,7 +545,7 @@ mr_clause
 
 split_clause
     : ^( SPLIT  { sb.append($SPLIT.text).append(" "); }
-        rel { sb.append(" INTO "); } split_branch ( { sb.append(", "); } split_branch )* split_otherwise? )
+        rel { sb.append(" INTO "); } split_branch ( { sb.append(", "); } split_branch )* ( { sb.append(", "); } split_otherwise )? )
 ;
 
 split_branch
@@ -553,7 +553,7 @@ split_branch
 ;
 
 split_otherwise
-    : ^( OTHERWISE { sb.append($OTHERWISE.text).append(" "); } alias )
+    : ^( OTHERWISE alias { sb.append(" " + $OTHERWISE.text); } )
 ;
 
 col_ref : alias_col_ref | dollar_col_ref

Modified: pig/trunk/test/org/apache/pig/test/TestMacroExpansion.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestMacroExpansion.java?rev=1491314&r1=1491313&r2=1491314&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestMacroExpansion.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestMacroExpansion.java Mon Jun 10 00:31:05 2013
@@ -439,6 +439,25 @@ public class TestMacroExpansion {
         
         verify(macro + script, expected);
     }
+
+    @Test
+    public void splitOtherwiseTest() throws Exception {
+        String macro = "define group_and_count (A,key) returns B {\n" +
+            "SPLIT $A INTO $B IF $key<7, Y IF $key==5, Z OTHERWISE;\n" +
+            "};\n";
+
+        String script =
+            "alpha = load 'users' as (f1:int);\n" +
+            "gamma = group_and_count (alpha, f1);\n" +
+            "store gamma into 'byuser';\n";
+
+        String expected =
+            "alpha = load 'users' as f1:int;\n" +
+            "SPLIT alpha INTO gamma IF f1 < 7, macro_group_and_count_Y_0 IF f1 == 5, macro_group_and_count_Z_0 OTHERWISE;\n" +
+            "store gamma INTO 'byuser';\n";
+
+        verify(macro + script, expected);
+    }
     
     @Test
     public void mapreduceTest() throws Exception {