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/16 21:11:55 UTC

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

Author: daijy
Date: Thu Feb 16 20:11:55 2012
New Revision: 1245154

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

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

Modified: pig/branches/branch-0.10/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/CHANGES.txt?rev=1245154&r1=1245153&r2=1245154&view=diff
==============================================================================
--- pig/branches/branch-0.10/CHANGES.txt (original)
+++ pig/branches/branch-0.10/CHANGES.txt Thu Feb 16 20:11:55 2012
@@ -166,6 +166,8 @@ PIG-2228: support partial aggregation in
 
 BUG FIXES
 
+PIG-2530: Reusing alias name in nested foreach causes incorrect results (daijy)
+
 PIG-2489: Input Path Globbing{} not working with PigStorageSchema or PigStorage('\t', '-schema') (daijy)
 
 PIG-2484: Fix several e2e test failures/aborts for 23 (daijy)

Modified: pig/branches/branch-0.10/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1245154&r1=1245153&r2=1245154&view=diff
==============================================================================
--- pig/branches/branch-0.10/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/branches/branch-0.10/src/org/apache/pig/parser/LogicalPlanGenerator.g Thu Feb 16 20:11:55 2012
@@ -1142,6 +1142,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.10/test/org/apache/pig/test/TestForEachNestedPlan.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/test/org/apache/pig/test/TestForEachNestedPlan.java?rev=1245154&r1=1245153&r2=1245154&view=diff
==============================================================================
--- pig/branches/branch-0.10/test/org/apache/pig/test/TestForEachNestedPlan.java (original)
+++ pig/branches/branch-0.10/test/org/apache/pig/test/TestForEachNestedPlan.java Thu Feb 16 20:11:55 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