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 2013/01/09 06:30:28 UTC

svn commit: r1430689 - in /pig/trunk: CHANGES.txt src/org/apache/pig/builtin/Distinct.java test/org/apache/pig/test/TestBuiltin.java

Author: daijy
Date: Wed Jan  9 05:30:27 2013
New Revision: 1430689

URL: http://svn.apache.org/viewvc?rev=1430689&view=rev
Log:
PIG-3115: Distinct Build-in Function Doesn't Handle Null Bags

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/builtin/Distinct.java
    pig/trunk/test/org/apache/pig/test/TestBuiltin.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1430689&r1=1430688&r2=1430689&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Wed Jan  9 05:30:27 2013
@@ -66,6 +66,8 @@ PIG-3013: BinInterSedes improve chararra
 
 BUG FIXES
 
+PIG-3115: Distinct Build-in Function Doesn't Handle Null Bags (njw45 via daijy)
+
 PIG-2433: Jython import module not working if module path is in classpath (rohini)
 
 PIG-2769 a simple logic causes very long compiling time on pig 0.10.0 (nwhite via gates)

Modified: pig/trunk/src/org/apache/pig/builtin/Distinct.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/Distinct.java?rev=1430689&r1=1430688&r2=1430689&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/Distinct.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/Distinct.java Wed Jan  9 05:30:27 2013
@@ -83,7 +83,8 @@ public class Distinct  extends EvalFunc<
             // representing the data we want to distinct. 
             // unwrap, put in a bag and send down
             try {
-                DataBag bag = new SingleTupleBag((Tuple)input.get(0));
+                Tuple single = (Tuple)input.get(0);
+                DataBag bag = single == null ? createDataBag() : new SingleTupleBag(single);
                 return tupleFactory.newTuple(bag);
             } catch (ExecException e) {
                 throw e;
@@ -133,6 +134,9 @@ public class Distinct  extends EvalFunc<
         long progressCounter = 0;
         try {
             DataBag bg = (DataBag)input.get(0);
+            if (bg == null) {
+                return result;
+            }
             for (Tuple tuple : bg) {
                 // Each tuple has a single column
                 // which is a bag. Get tuples out of it
@@ -155,6 +159,9 @@ public class Distinct  extends EvalFunc<
         try {
             DataBag inputBg = (DataBag)input.get(0);
             DataBag result = createDataBag();
+            if (inputBg == null) {
+                return result;
+            }
             long progressCounter = 0;
             for (Tuple tuple : inputBg) {
                 result.add(tuple);

Modified: pig/trunk/test/org/apache/pig/test/TestBuiltin.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestBuiltin.java?rev=1430689&r1=1430688&r2=1430689&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestBuiltin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestBuiltin.java Wed Jan  9 05:30:27 2013
@@ -18,7 +18,6 @@
 package org.apache.pig.test;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -54,7 +53,6 @@ import org.apache.pig.builtin.COR;
 import org.apache.pig.builtin.COUNT;
 import org.apache.pig.builtin.COUNT_STAR;
 import org.apache.pig.builtin.COV;
-import org.apache.pig.builtin.CurrentTime;
 import org.apache.pig.builtin.DIFF;
 import org.apache.pig.builtin.DaysBetween;
 import org.apache.pig.builtin.Distinct;
@@ -2014,6 +2012,17 @@ public class TestBuiltin {
     }
 
     @Test
+    public void testDistinctIsNullSafe() throws Exception {
+        DataBag empty = bagFactory.newDefaultBag();
+        Tuple tupleOfNull = tupleFactory.newTuple(1);
+        Tuple tupleOfEmpty = tupleFactory.newTuple(empty);
+        assertEquals(empty, new Distinct().exec(tupleOfNull));
+        assertEquals(tupleOfEmpty, new Distinct.Initial().exec(tupleOfNull));
+        assertEquals(tupleOfEmpty, new Distinct.Intermediate().exec(tupleOfNull));
+        assertEquals(empty, new Distinct.Final().exec(tupleOfNull));
+    }
+
+    @Test
     public void testDistinctProgressNonAlgebraic() throws Exception {
 
         //This test is for the exec method in Distinct which is not