You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by sm...@apache.org on 2009/03/07 01:35:43 UTC

svn commit: r751147 - in /hadoop/pig/trunk: CHANGES.txt src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt test/org/apache/pig/test/TestLogicalPlanBuilder.java

Author: sms
Date: Sat Mar  7 00:35:42 2009
New Revision: 751147

URL: http://svn.apache.org/viewvc?rev=751147&view=rev
Log:
PIG-532: Casting a field removes its alias.(thejas via sms)

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=751147&r1=751146&r2=751147&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Sat Mar  7 00:35:42 2009
@@ -452,3 +452,5 @@
 
     PIG-544: Utf8StorageConverter.java does not always produce NULLs when data
     is malformed(thejas via sms)
+
+    PIG-532: Casting a field removes its alias.(thejas via sms)

Modified: hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=751147&r1=751146&r2=751147&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt (original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt Sat Mar  7 00:35:42 2009
@@ -2497,6 +2497,7 @@
     {
         if(castRequired) {
             cast = new LOCast(lp, new OperatorKey(scope, getNextId()), exprOp, fs.type);
+            fs.alias = exprOp.getFieldSchema().alias;
             cast.setFieldSchema(fs);
             lp.add(cast);
 		    log.debug("Added operator " + cast.getClass().getName() + " " + cast + " to logical plan " + lp);

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=751147&r1=751146&r2=751147&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java Sat Mar  7 00:35:42 2009
@@ -1539,33 +1539,33 @@
         buildPlan("a = load 'a';");
         buildPlan("store a into 'out' using PigStorage();");
     }
-    
+
     @Test
     public void testQuery104() {
         // check that a field alias can be referenced
         // by unambiguous free form alias, fully qualified alias
         // and partially qualified unambiguous alias
-        String query = "a = load 'st10k' as (name, age, gpa);" +
-            "b = group a by name;" +
-            "c = foreach b generate flatten(a);" +
-            "d = filter c by name != 'fred';" +
-            "e = group d by name;" +
-            "f = foreach e generate flatten(d);" +
-            "g = foreach f generate name, d::a::name, a::name;";
-        buildPlan(query);
+        buildPlan( "a = load 'st10k' as (name, age, gpa);" );
+        buildPlan( "b = group a by name;" );
+        buildPlan("c = foreach b generate flatten(a);" );
+        buildPlan("d = filter c by name != 'fred';" );
+        buildPlan("e = group d by name;" );
+        buildPlan("f = foreach e generate flatten(d);" );
+        buildPlan("g = foreach f generate name, d::a::name, a::name;");
+
     }
-    
+
     @Test
     public void testQuery105() {
         // test that the alias "group" can be used
         // after a flatten(group)
-        String query = "a = load 'st10k' as (name, age, gpa);" +
-            "b = group a by name;" +
-            "c = foreach b generate flatten(group), COUNT(a) as cnt;" +
-            "d = foreach c generate group;";
-        buildPlan(query);
+        buildPlan( "a = load 'st10k' as (name, age, gpa);" );
+        buildPlan("b = group a by name;" );
+        buildPlan("c = foreach b generate flatten(group), COUNT(a) as cnt;" );
+        buildPlan("d = foreach c generate group;");
+
     }
-    
+
     @Test
     public void testQuery106()  throws FrontendException, ParseException {
         LogicalPlan lp;
@@ -1796,87 +1796,101 @@
 
     @Test
     public void testNullConsArithExprs() {
-        String query = "a = load 'a' as (x:int, y:double);" +
-        		"b = foreach a generate x + null, x * null, x / null, x - null, null % x, " +
-                "y + null, y * null, y / null, y - null;";
-        buildPlan(query);
+        buildPlan("a = load 'a' as (x:int, y:double);" );
+        buildPlan("b = foreach a generate x + null, x * null, x / null, x - null, null % x, " +
+                "y + null, y * null, y / null, y - null;"
+        );
     }
-    
+
     @Test
     public void testNullConsBincond1() {
-        String query = "a = load 'a' as (x:int, y:double);" +
-        		"b = foreach a generate (2 > 1? null : 1), ( 2 < 1 ? null : 1), " +
-        		"(2 > 1 ? 1 : null), ( 2 < 1 ? 1 : null);";
-        buildPlan(query);
+        buildPlan("a = load 'a' as (x:int, y:double);" );
+        buildPlan("b = foreach a generate (2 > 1? null : 1), ( 2 < 1 ? null : 1), " +
+                "(2 > 1 ? 1 : null), ( 2 < 1 ? 1 : null);"
+        );
     }
-    
+
     @Test
     public void testNullConsBincond2() {
-        String query = "a = load 'a' as (x:int, y:double);" +
-                 "b = foreach a generate (null is null ? 1 : 2), ( null is not null ? 2 : 1);";
-        buildPlan(query);
+        buildPlan("a = load 'a' as (x:int, y:double);" );
+        buildPlan("b = foreach a generate (null is null ? 1 : 2), ( null is not null ? 2 : 1);");
     }
-    
+
     @Test
     public void testNullConsForEachGenerate() {
-        String query = "a = load 'a' as (x:int, y:double);" +
-        		"b = foreach a generate x, null, y, null;";
-        buildPlan(query);
+        buildPlan("a = load 'a' as (x:int, y:double);" );
+        buildPlan("b = foreach a generate x, null, y, null;");
+
     }
-    
+
     @Test
     public void testNullConsOuterJoin() {
-        String query = "a = load 'a' as (x:int, y:chararray);" +
-        		"b = load 'b' as (u:int, v:chararray);" +
-        		"c = cogroup a by x, b by u;" +
-        		"d = foreach c generate flatten((SIZE(a) == 0 ? null : a)), " +
-        		"flatten((SIZE(b) == 0 ? null : b));";
-        buildPlan(query);
+        buildPlan("a = load 'a' as (x:int, y:chararray);" );
+        buildPlan("b = load 'b' as (u:int, v:chararray);" );
+        buildPlan("c = cogroup a by x, b by u;" );
+        buildPlan("d = foreach c generate flatten((SIZE(a) == 0 ? null : a)), " +
+                "flatten((SIZE(b) == 0 ? null : b));"
+        );
     }
-    
+
     @Test
     public void testNullConsConcatSize() {
-        String query = "a = load 'a' as (x:int, y:double, str:chararray);" +
-        		"b = foreach a generate SIZE(null), CONCAT(str, null), " +
-        "CONCAT(null, str);";
-        buildPlan(query);
+        buildPlan("a = load 'a' as (x:int, y:double, str:chararray);" );
+        buildPlan("b = foreach a generate SIZE(null), CONCAT(str, null), " + 
+                "CONCAT(null, str);"
+        );
     }
 
     @Test
     public void testFilterUdfDefine() {
-        String query = "define isempty IsEmpty(); a = load 'a' as (x:int, y:double, str:chararray);" +
-        		"b = filter a by isempty(*);";
-        buildPlan(query);
+        buildPlan("define isempty IsEmpty();");
+        buildPlan("a = load 'a' as (x:int, y:double, str:chararray);");
+        buildPlan("b = filter a by isempty(*);");
     }
-    
+
     @Test
     public void testLoadUdfDefine() {
-        String query = "define PS PigStorage(); a = load 'a' using PS as (x:int, y:double, str:chararray);" +
-        		"b = filter a by IsEmpty(*);";
-        buildPlan(query);
+        buildPlan("define PS PigStorage();");
+        buildPlan("a = load 'a' using PS as (x:int, y:double, str:chararray);" );
+        buildPlan("b = filter a by IsEmpty(*);");
     }
-    
+
     @Test
     public void testLoadUdfConstructorArgDefine() {
-        String query = "define PS PigStorage(':'); a = load 'a' using PS as (x:int, y:double, str:chararray);" +
-        		"b = filter a by IsEmpty(*);";
-        buildPlan(query);
+        buildPlan("define PS PigStorage(':');");
+        buildPlan("a = load 'a' using PS as (x:int, y:double, str:chararray);" );
+        buildPlan("b = filter a by IsEmpty(*);");
     }
-    
+
     @Test
     public void testStoreUdfDefine() {
-        String query = "define PS PigStorage(); a = load 'a' using PS as (x:int, y:double, str:chararray);" +
-        		"b = filter a by IsEmpty(*);" +
-                "store b into 'x' using PS;" ;
-        buildPlan(query);
+        buildPlan( "define PS PigStorage();");
+        buildPlan("a = load 'a' using PS as (x:int, y:double, str:chararray);" );
+        buildPlan("b = filter a by IsEmpty(*);" );
+        buildPlan("store b into 'x' using PS;");
     }
-    
+
     @Test
     public void testStoreUdfConstructorArgDefine() {
-        String query = "define PS PigStorage(':'); a = load 'a' using PS as (x:int, y:double, str:chararray);" +
-        		"b = filter a by IsEmpty(*);" +
-                "store b into 'x' using PS;" ;
-        buildPlan(query);
+        buildPlan( "define PS PigStorage(':');");
+        buildPlan(" a = load 'a' using PS as (x:int, y:double, str:chararray);" );
+        buildPlan(" b = filter a by IsEmpty(*);" );
+        buildPlan(" store b into 'x' using PS;") ;
+
+    }
+
+    @Test
+    public void testCastAlias() {
+        buildPlan("a = load 'one.txt' as (x,y); ");
+        buildPlan("b =  foreach a generate (int)x, (double)y;");
+        buildPlan("c = group b by x;");
+    }
+
+    @Test
+    public void testCast() {
+        buildPlan("a = load 'one.txt' as (x,y); " );
+        buildPlan("b = foreach a generate (int)$0, (double)$1;" ); 
+        buildPlan("c = group b by $0;");
     }