Author: daijy
Date: Fri Sep  3 21:46:09 2010
New Revision: 992486

URL: http://svn.apache.org/viewvc?rev=992486&view=rev
Log:
PIG-1543: IsEmpty returns the wrong value after using LIMIT

Modified:
    hadoop/pig/trunk/CHANGES.txt
    
hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POProject.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestEvalPipeline2.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=992486&r1=992485&r2=992486&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Fri Sep  3 21:46:09 2010
@@ -195,6 +195,8 @@ PIG-1309: Map-side Cogroup (ashutoshc)
 
 BUG FIXES
 
+PIG-1543: IsEmpty returns the wrong value after using LIMIT (daijy)
+
 PIG-1550:  better error handling in casting relations to scalars (thejas)
 
 PIG-1572: change default datatype when relations are used as scalar to 
bytearray (thejas)

Modified: 
hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POProject.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POProject.java?rev=992486&r1=992485&r2=992486&view=diff
==============================================================================
--- 
hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POProject.java
 (original)
+++ 
hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POProject.java
 Fri Sep  3 21:46:09 2010
@@ -384,6 +384,9 @@ public class POProject extends Expressio
                     processingBagOfTuples = true;
                     res.result = bagIterator.next();
                 }
+                // If the bag contains no tuple, set the returnStatus to 
STATUS_EOP
+                if (!processingBagOfTuples)
+                    res.returnStatus = POStatus.STATUS_EOP;
             }
             else {
                 res.result = (Tuple)ret;

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestEvalPipeline2.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestEvalPipeline2.java?rev=992486&r1=992485&r2=992486&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestEvalPipeline2.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestEvalPipeline2.java Fri Sep  3 
21:46:09 2010
@@ -712,4 +712,37 @@ public class TestEvalPipeline2 extends T
         
         assertFalse(iter.hasNext());
     }
+    
+    // See PIG-1543
+    @Test
+    public void testEmptyBagIterator() throws Exception{
+        String[] input1 = {
+                "1",
+                "1",
+                "1"
+        };
+        
+        String[] input2 = {
+                "2",
+                "2"
+        };
+        
+        Util.createInputFile(cluster, "input1", input1);
+        Util.createInputFile(cluster, "input2", input2);
+        pigServer.registerQuery("A = load 'input1' as (a1:int);");
+        pigServer.registerQuery("B = load 'input2' as (b1:int);");
+        pigServer.registerQuery("C = COGROUP A by a1, B by b1;");
+        pigServer.registerQuery("C1 = foreach C { Alim = limit A 1; Blim = 
limit B 1; generate Alim, Blim; };");
+        pigServer.registerQuery("D1 = FOREACH C1 generate Alim,Blim, 
(IsEmpty(Alim)? 0:1), (IsEmpty(Blim)? 0:1), COUNT(Alim), COUNT(Blim);");
+        
+        Iterator<Tuple> iter = pigServer.openIterator("D1");
+        
+        Tuple t = iter.next();
+        assertTrue(t.toString().equals("({(1)},{},1,0,1,0)"));
+        
+        t = iter.next();
+        assertTrue(t.toString().equals("({},{(2)},0,1,0,1)"));
+        
+        assertFalse(iter.hasNext());
+    }
 }


Reply via email to