Author: olga
Date: Wed Sep 24 13:35:01 2008
New Revision: 698718

URL: http://svn.apache.org/viewvc?rev=698718&view=rev
Log:
If an field is part of group followed by flatten, then referring to it causes a 
parse error

Modified:
    incubator/pig/branches/types/CHANGES.txt
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/schema/Schema.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=698718&r1=698717&r2=698718&view=diff
==============================================================================
--- incubator/pig/branches/types/CHANGES.txt (original)
+++ incubator/pig/branches/types/CHANGES.txt Wed Sep 24 13:35:01 2008
@@ -241,3 +241,7 @@
     PIG-448: explain broken after load with types (pradeepk via olgan)
 
     PIG-380: invalid schema for databag constant (sms via olgan)
+
+    PIG-451: If an field is part of group followed by flatten, then referring
+    to it causes a parse error (pradeepk via olgan)
+

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/schema/Schema.java?rev=698718&r1=698717&r2=698718&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
 Wed Sep 24 13:35:01 2008
@@ -20,6 +20,7 @@
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -554,6 +555,17 @@
                 }
                 return mAliases.get(key);
             } else {
+                // check if the multiple aliases obtained actually
+                // point to the same field schema - then just return
+                // that field schema
+                Set<FieldSchema> set = new HashSet<FieldSchema>();
+                for (String key: aliasMatches.keySet()) {
+                    set.add(mAliases.get(key));
+                }
+                if(set.size() == 1) {
+                    return set.iterator().next();
+                }
+                
                 boolean hasNext = false;
                 StringBuilder sb = new StringBuilder("Found more than one 
match: ");
                 for (String key: aliasMatches.keySet()) {

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=698718&r1=698717&r2=698718&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
 Wed Sep 24 13:35:01 2008
@@ -157,29 +157,7 @@
         assertTrue(lo instanceof LODefine);
     }
 
-    @Test
-    public void testQuery101() {
-        // test usage of an alias from define
-        String query = "define FUNC ARITY();";
-        buildPlan(query);
 
-        query = "foreach (load 'data') generate FUNC($0);";
-        buildPlan(query);
-    }
-
-    @Test
-    public void testQuery102() {
-        // test basic store
-        buildPlan("a = load 'a';");
-        buildPlan("store a into 'out';");
-    }
-
-    @Test
-    public void testQuery103() {
-        // test store with store function
-        buildPlan("a = load 'a';");
-        buildPlan("store a into 'out' using PigStorage();");
-    }
 
     @Test
     public void testQueryFail1() {
@@ -1517,6 +1495,45 @@
 
     }
 
+    @Test
+    public void testQuery101() {
+        // test usage of an alias from define
+        String query = "define FUNC ARITY();";
+        buildPlan(query);
+
+        query = "foreach (load 'data') generate FUNC($0);";
+        buildPlan(query);
+    }
+
+    @Test
+    public void testQuery102() {
+        // test basic store
+        buildPlan("a = load 'a';");
+        buildPlan("store a into 'out';");
+    }
+
+    @Test
+    public void testQuery103() {
+        // test store with store function
+        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);
+    }
+    
     private Schema getSchemaFromString(String schemaString) throws 
ParseException {
         return getSchemaFromString(schemaString, DataType.BYTEARRAY);
     }


Reply via email to