pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1203105 - in /pig/branches/branch-0.10: CHANGES.txt src/org/apache/pig/parser/PigMacro.java src/org/apache/pig/parser/QueryParser.g test/org/apache/pig/test/TestMacroExpansion.java
Date Thu, 17 Nov 2011 08:36:13 GMT
Author: daijy
Date: Thu Nov 17 08:36:12 2011
New Revision: 1203105

URL: http://svn.apache.org/viewvc?rev=1203105&view=rev
Log:
PIG-2184: Not able to provide positional reference to macro invocations

Modified:
    pig/branches/branch-0.10/CHANGES.txt
    pig/branches/branch-0.10/src/org/apache/pig/parser/PigMacro.java
    pig/branches/branch-0.10/src/org/apache/pig/parser/QueryParser.g
    pig/branches/branch-0.10/test/org/apache/pig/test/TestMacroExpansion.java

Modified: pig/branches/branch-0.10/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/CHANGES.txt?rev=1203105&r1=1203104&r2=1203105&view=diff
==============================================================================
--- pig/branches/branch-0.10/CHANGES.txt (original)
+++ pig/branches/branch-0.10/CHANGES.txt Thu Nov 17 08:36:12 2011
@@ -150,6 +150,8 @@ PIG-2228: support partial aggregation in
 
 BUG FIXES
 
+PIG-2184: Not able to provide positional reference to macro invocations (daijy)
+
 PIG-2209: JsonMetadata fails to find schema for glob paths (daijy)
 
 PIG-2352: e2e test harness' use of environment variables causes unintended effects between
tests (gates)

Modified: pig/branches/branch-0.10/src/org/apache/pig/parser/PigMacro.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/src/org/apache/pig/parser/PigMacro.java?rev=1203105&r1=1203104&r2=1203105&view=diff
==============================================================================
--- pig/branches/branch-0.10/src/org/apache/pig/parser/PigMacro.java (original)
+++ pig/branches/branch-0.10/src/org/apache/pig/parser/PigMacro.java Thu Nov 17 08:36:12 2011
@@ -138,6 +138,8 @@ class PigMacro {
         
         String[] args = new String[params.size()];
         for (int i=0; i<params.size(); i++) {
+        	 if (inputs[i].startsWith("$"))
+        		 inputs[i]="\\\\"+inputs[i];
             args[i] = params.get(i) + "=" + inputs[i];
         }
         if (!isVoidReturn) {

Modified: pig/branches/branch-0.10/src/org/apache/pig/parser/QueryParser.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/src/org/apache/pig/parser/QueryParser.g?rev=1203105&r1=1203104&r2=1203105&view=diff
==============================================================================
--- pig/branches/branch-0.10/src/org/apache/pig/parser/QueryParser.g (original)
+++ pig/branches/branch-0.10/src/org/apache/pig/parser/QueryParser.g Thu Nov 17 08:36:12 2011
@@ -197,6 +197,7 @@ parameter 
     | INTEGER 
     | DOUBLENUMBER
     | QUOTEDSTRING
+    | DOLLARVAR
 ;
 
 content : LEFT_CURLY ( content | ~(LEFT_CURLY | RIGHT_CURLY) )* RIGHT_CURLY

Modified: pig/branches/branch-0.10/test/org/apache/pig/test/TestMacroExpansion.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/test/org/apache/pig/test/TestMacroExpansion.java?rev=1203105&r1=1203104&r2=1203105&view=diff
==============================================================================
--- pig/branches/branch-0.10/test/org/apache/pig/test/TestMacroExpansion.java (original)
+++ pig/branches/branch-0.10/test/org/apache/pig/test/TestMacroExpansion.java Thu Nov 17 08:36:12
2011
@@ -1210,27 +1210,23 @@ public class TestMacroExpansion {
         validateFailure(sb.toString(), expectedErr, "at");
     }
     
-    @Test // PIG-2081
-    public void lineNumberTest3() throws Throwable {
-        StringBuilder sb = new StringBuilder();
-        
-        sb.append("DEFINE my_macro (X,key) returns Y\n" +
-            "{\n" +   
-            "tmp1 = foreach  $X generate TOKENIZE((chararray)$key) as tokens;\n" +
-            "tmp2 = foreach tmp1 generate flatten(tokens);\n" +
-            "tmp3 = order tmp2 by $0;\n" + 
-            "$Y = distinct tmp3;\n" +
-            "};\n");
-        
-        sb.append("A3 = load 'sometext3' using TextLoader() as (row3);\n");
-        
-        sb.append("E3 = my_macro(A3,$0);\n");
-
-        
-        String expectedErr = 
-            "<file myscript.pig, line 9, column 17>  Syntax error, unexpected symbol
at or near '$0'";
-        
-        validateDryrunFailure(sb.toString(), expectedErr, "<file");
+    //see Pig-2184
+    @Test
+    public void testMacroAliasConversion() throws Exception {
+    	  String macro = "define my_macro (X,key) returns Y {\n" +
+    	        "$Y = filter $X by $key>0;\n" +
+    	            "};\n";
+    	        
+    	        String script = 
+    	            "A = load 'sometext1' using TextLoader() as (row1) ;\n" +
+    	            "E = my_macro (A, $0);\n" +
+    	            "store E into 'byrow1';\n";
+    	        
+    	        String expected =
+    	        			"A = load 'sometext1' USING TextLoader() as row1;\n"+
+    	        			"E = filter A BY ($0 > 0);\n"+
+    	        			"store E INTO 'byrow1';\n";
+    	        verify(macro + script, expected);
     }
     
     @Test



Mime
View raw message