You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by jc...@apache.org on 2012/10/19 01:48:27 UTC

svn commit: r1399926 - in /pig/trunk: src/org/apache/pig/builtin/COUNT.java test/org/apache/pig/test/TestBuiltin.java

Author: jcoveney
Date: Thu Oct 18 23:48:27 2012
New Revision: 1399926

URL: http://svn.apache.org/viewvc?rev=1399926&view=rev
Log:
Properly commit PIG-1283

Modified:
    pig/trunk/src/org/apache/pig/builtin/COUNT.java
    pig/trunk/test/org/apache/pig/test/TestBuiltin.java

Modified: pig/trunk/src/org/apache/pig/builtin/COUNT.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/COUNT.java?rev=1399926&r1=1399925&r2=1399926&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/COUNT.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/COUNT.java Thu Oct 18 23:48:27 2012
@@ -58,6 +58,9 @@ public class COUNT extends EvalFunc<Long
     public Long exec(Tuple input) throws IOException {
         try {
             DataBag bag = (DataBag)input.get(0);
+            if(bag==null)
+                return null;
+
             Iterator it = bag.iterator();
             long cnt = 0;
             while (it.hasNext()){

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=1399926&r1=1399925&r2=1399926&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestBuiltin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestBuiltin.java Thu Oct 18 23:48:27 2012
@@ -18,6 +18,7 @@
 package org.apache.pig.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
@@ -1001,6 +1002,17 @@ public class TestBuiltin {
     }
 
     @Test
+    public void testCOUNTBagNullCheck() throws Exception{
+
+        DataBag b = null;
+        Tuple t = tupleFactory.getInstance().newTuple(b);
+
+        EvalFunc<Long> count = new COUNT();
+        assertNull(count.exec(t));
+       }
+
+
+    @Test
     public void testCount_ValidNumberOfArguments_WithoutInputSchema_One() throws Exception {
          File inputFile = createCountInputFile();
          try {