pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject svn commit: r696824 - in /incubator/pig/branches/types: CHANGES.txt src/org/apache/pig/impl/logicalLayer/LOForEach.java test/org/apache/pig/test/TestLogicalPlanBuilder.java
Date Thu, 18 Sep 2008 21:34:33 GMT
Author: olga
Date: Thu Sep 18 14:34:33 2008
New Revision: 696824

URL: http://svn.apache.org/viewvc?rev=696824&view=rev
Log:
PIG-436: When a single column is flattened, the alias is lost in subsequent statements that
refer to the alias

Modified:
    incubator/pig/branches/types/CHANGES.txt
    incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOForEach.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java

Modified: incubator/pig/branches/types/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/CHANGES.txt?rev=696824&r1=696823&r2=696824&view=diff
==============================================================================
--- incubator/pig/branches/types/CHANGES.txt (original)
+++ incubator/pig/branches/types/CHANGES.txt Thu Sep 18 14:34:33 2008
@@ -202,6 +202,12 @@
 
     PIG-434: short-circuit AND and OR (pradeepk viia olgan)
 
-    PIG-333: allowing no parethesis with single column alias with flatten
+    PIG-333: allowing no parethesis with single column alias with flatten (sms
+    via olgan)
+
+    PIG-426: Adding result of two UDFs gives a syntax error (sms via olgan)
+
+    PIG-436: alias is lost when single column is flattened (pradeepk via
+    olgan)
+
 
-    PIG-426: Adding result of two UDFs gives a syntax error

Modified: incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOForEach.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOForEach.java?rev=696824&r1=696823&r2=696824&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOForEach.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOForEach.java Thu Sep
18 14:34:33 2008
@@ -325,6 +325,9 @@
 				log.debug("alias: " + alias);
 				if((null != alias) && (count == 1)) {
 					mSchema.addAlias(alias, fs);
+					// alias is unambiguous - so set it
+					// as the alias in the field schema
+					fs.alias = alias;
 				}
 			}
             mIsSchemaComputed = true;

Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=696824&r1=696823&r2=696824&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java Thu
Sep 18 14:34:33 2008
@@ -1273,7 +1273,7 @@
             assertTrue(e.getMessage().contains("Schema size mismatch"));
         }
     }
-
+        
     @Test
     public void testQuery91() {
         buildPlan("a = load 'myfile' as (name:Chararray, age:Int, gpa:Float);");
@@ -1293,6 +1293,58 @@
         + "};";
     }
 
+    @Test
+    public void testQuery93() throws FrontendException, ParseException {
+        buildPlan("a = load 'one' as (name, age, gpa);");
+        buildPlan("b = group a by name;");
+        buildPlan("c = foreach b generate flatten(a);");
+        buildPlan("d = foreach c generate name;");
+        // test that we can refer to "name" field and not a::name
+        buildPlan("e = foreach d generate name;");
+    }
+    
+    @Test
+    public void testQueryFail93() throws FrontendException, ParseException {
+        buildPlan("a = load 'one' as (name, age, gpa);");
+        buildPlan("b = group a by name;");
+        buildPlan("c = foreach b generate flatten(a);");
+        buildPlan("d = foreach c generate name;");
+        // test that we can refer to "name" field and not a::name
+        try {
+            buildPlan("e = foreach d generate a::name;");
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Invalid alias: a::name in {name: bytearray}"));
+        }
+    }
+    
+    @Test
+    public void testQuery94() throws FrontendException, ParseException {
+        buildPlan("a = load 'one' as (name, age, gpa);");
+        buildPlan("b = load 'two' as (name, age, somethingelse);");
+        buildPlan("c = cogroup a by name, b by name;");
+        buildPlan("d = foreach c generate flatten(a), flatten(b);");
+        // test that we can refer to "a::name" field and not name
+        // test that we can refer to "b::name" field and not name
+        buildPlan("e = foreach d generate a::name, b::name;");
+        // test that we can refer to gpa and somethingelse
+        buildPlan("f = foreach d generate gpa, somethingelse, a::gpa, b::somethingelse;");
+        
+    }
+    
+    @Test
+    public void testQueryFail94() throws FrontendException, ParseException {
+        buildPlan("a = load 'one' as (name, age, gpa);");
+        buildPlan("b = load 'two' as (name, age, somethingelse);");
+        buildPlan("c = cogroup a by name, b by name;");
+        buildPlan("d = foreach c generate flatten(a), flatten(b);");
+        // test that we can refer to "a::name" field and not name
+        try {
+            buildPlan("e = foreach d generate name;");
+        } catch (AssertionFailedError e) {
+            assertTrue(e.getMessage().contains("Invalid alias: name in {a::name: bytearray"));
+        }
+    }
+
     private Schema getSchemaFromString(String schemaString) throws ParseException {
         return getSchemaFromString(schemaString, DataType.BYTEARRAY);
     }



Mime
View raw message