You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2012/02/21 03:32:19 UTC

svn commit: r1291560 - in /pig/branches/branch-0.9: CHANGES.txt src/org/apache/pig/parser/LogicalPlanGenerator.g test/org/apache/pig/test/TestForEachNestedPlan.java

Author: daijy
Date: Tue Feb 21 02:32:19 2012
New Revision: 1291560

URL: http://svn.apache.org/viewvc?rev=1291560&view=rev
Log:
PIG-2530: Reusing alias name in nested foreach causes incorrect results

Modified:
    pig/branches/branch-0.9/CHANGES.txt
    pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g
    pig/branches/branch-0.9/test/org/apache/pig/test/TestForEachNestedPlan.java

Modified: pig/branches/branch-0.9/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/CHANGES.txt?rev=1291560&r1=1291559&r2=1291560&view=diff
==============================================================================
--- pig/branches/branch-0.9/CHANGES.txt (original)
+++ pig/branches/branch-0.9/CHANGES.txt Tue Feb 21 02:32:19 2012
@@ -28,6 +28,8 @@ PIG-2497: Order of execution of fs, stor
 
 PIG-2508: PIG can unpredictably ignore deprecated Hadoop config options (thw via daijy)
 
+PIG-2530: Reusing alias name in nested foreach causes incorrect results (daijy)
+
 Release 0.9.2
 
 IMPROVEMENTS

Modified: pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1291560&r1=1291559&r2=1291560&view=diff
==============================================================================
--- pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/branches/branch-0.9/src/org/apache/pig/parser/LogicalPlanGenerator.g Tue Feb 21 02:32:19 2012
@@ -1133,6 +1133,7 @@ nested_command
  : ^( NESTED_CMD IDENTIFIER nested_op[$IDENTIFIER.text] )
    {
        $foreach_plan::operators.put( $IDENTIFIER.text, $nested_op.op );
+       $foreach_plan::exprPlans.remove( $IDENTIFIER.text );
    }
  | 
    ^( NESTED_CMD_ASSI IDENTIFIER expr[exprPlan] )

Modified: pig/branches/branch-0.9/test/org/apache/pig/test/TestForEachNestedPlan.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/test/org/apache/pig/test/TestForEachNestedPlan.java?rev=1291560&r1=1291559&r2=1291560&view=diff
==============================================================================
--- pig/branches/branch-0.9/test/org/apache/pig/test/TestForEachNestedPlan.java (original)
+++ pig/branches/branch-0.9/test/org/apache/pig/test/TestForEachNestedPlan.java Tue Feb 21 02:32:19 2012
@@ -238,6 +238,52 @@ public class TestForEachNestedPlan {
             }
         }
     }
+
+    @Test
+    public void testInnerOrderByAliasReuse() 
+    throws IOException, ParserException {
+        String INPUT_FILE = "test-innerorderbyaliasreuse.txt";
+
+        PrintWriter w = new PrintWriter(new FileWriter(INPUT_FILE));
+        w.println("1\t4");
+        w.println("1\t3");
+        w.println("2\t3");
+        w.println("2\t4");
+        w.close();
+
+        try {
+            Util.copyFromLocalToCluster(cluster, INPUT_FILE, INPUT_FILE);
+        
+            pig.registerQuery("A = load '" + INPUT_FILE
+                    + "' as (v1:int, v2:int);");
+            pig.registerQuery("B = group A by v1;");
+            pig.registerQuery("C = foreach B { X = A; X = order X by v2 asc; " +
+            		"generate flatten(X); };");
+    
+            Iterator<Tuple> iter = pig.openIterator("C");
+
+            List<Tuple> expectedResults =
+                Util.getTuplesFromConstantTupleStrings(
+                        new String[] {"(1,3)", "(1,4)", "(2,3)", "(2,4)"});
+
+            int counter = 0;
+            while (iter.hasNext()) {
+                assertEquals(expectedResults.get(counter++).toString(),
+                        iter.next().toString());                
+            }
+    
+            assertEquals(expectedResults.size(), counter);
+        } finally{
+            new File(INPUT_FILE).delete();
+            try {
+                Util.deleteFile(cluster, INPUT_FILE);
+            } catch (IOException e) {
+                e.printStackTrace();
+                Assert.fail();
+            }
+        }
+    }
+    
     
     /***
      * For generating a sample dataset