Author: rohini
Date: Mon Jan 11 00:18:15 2016
New Revision: 1723972

URL: http://svn.apache.org/viewvc?rev=1723972&view=rev
Log:
PIG-4774: Fix NPE in SUM,AVG,MIN,MAX UDFs for null bag input (rohini)

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/builtin/AVG.java
    pig/trunk/src/org/apache/pig/builtin/AlgebraicBigDecimalMathBase.java
    pig/trunk/src/org/apache/pig/builtin/AlgebraicBigIntegerMathBase.java
    pig/trunk/src/org/apache/pig/builtin/AlgebraicByteArrayMathBase.java
    pig/trunk/src/org/apache/pig/builtin/AlgebraicDoubleMathBase.java
    pig/trunk/src/org/apache/pig/builtin/AlgebraicFloatMathBase.java
    pig/trunk/src/org/apache/pig/builtin/AlgebraicIntMathBase.java
    pig/trunk/src/org/apache/pig/builtin/AlgebraicLongMathBase.java
    pig/trunk/src/org/apache/pig/builtin/BigDecimalAvg.java
    pig/trunk/src/org/apache/pig/builtin/BigIntegerAvg.java
    pig/trunk/src/org/apache/pig/builtin/DateTimeMax.java
    pig/trunk/src/org/apache/pig/builtin/DateTimeMin.java
    pig/trunk/src/org/apache/pig/builtin/DoubleAvg.java
    pig/trunk/src/org/apache/pig/builtin/FloatAvg.java
    pig/trunk/src/org/apache/pig/builtin/IntAvg.java
    pig/trunk/src/org/apache/pig/builtin/LongAvg.java
    pig/trunk/src/org/apache/pig/builtin/StringMax.java
    pig/trunk/src/org/apache/pig/builtin/StringMin.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=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Mon Jan 11 00:18:15 2016
@@ -77,6 +77,8 @@ PIG-4639: Add better parser for Apache H
 
 BUG FIXES
 
+PIG-4774: Fix NPE in SUM,AVG,MIN,MAX UDFs for null bag input (rohini)
+
 PIG-4757: Job stats on successfully read/output records wrong with multiple 
inputs/outputs (rohini)
 
 PIG-4769: UnionOptimizer hits errors when merging vertex group into split 
(rohini)

Modified: pig/trunk/src/org/apache/pig/builtin/AVG.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AVG.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AVG.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/AVG.java Mon Jan 11 00:18:15 2016
@@ -27,6 +27,7 @@ import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
 import org.apache.pig.FuncSpec;
 import org.apache.pig.PigException;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataByteArray;
 import org.apache.pig.data.DataType;
@@ -34,7 +35,6 @@ import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.FrontendException;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
-import org.apache.pig.backend.executionengine.ExecException;
 
 
 /**
@@ -79,14 +79,17 @@ public class AVG extends EvalFunc<Double
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -230,7 +233,7 @@ public class AVG extends EvalFunc<Double
         DataBag values = (DataBag)input.get(0);
 
         // if we were handed an empty bag, return NULL
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 

Modified: pig/trunk/src/org/apache/pig/builtin/AlgebraicBigDecimalMathBase.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AlgebraicBigDecimalMathBase.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AlgebraicBigDecimalMathBase.java 
(original)
+++ pig/trunk/src/org/apache/pig/builtin/AlgebraicBigDecimalMathBase.java Mon 
Jan 11 00:18:15 2016
@@ -18,8 +18,8 @@
 package org.apache.pig.builtin;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.math.BigDecimal;
+import java.util.Iterator;
 
 import org.apache.pig.Accumulator;
 import org.apache.pig.PigException;
@@ -88,7 +88,7 @@ public abstract class AlgebraicBigDecima
         DataBag values = (DataBag)input.get(0);
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
         BigDecimal sofar = 
AlgebraicBigDecimalMathBase.getSeed(opProvider.getOp());

Modified: pig/trunk/src/org/apache/pig/builtin/AlgebraicBigIntegerMathBase.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AlgebraicBigIntegerMathBase.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AlgebraicBigIntegerMathBase.java 
(original)
+++ pig/trunk/src/org/apache/pig/builtin/AlgebraicBigIntegerMathBase.java Mon 
Jan 11 00:18:15 2016
@@ -18,8 +18,8 @@
 package org.apache.pig.builtin;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.math.BigInteger;
+import java.util.Iterator;
 
 import org.apache.pig.Accumulator;
 import org.apache.pig.PigException;
@@ -88,7 +88,7 @@ public abstract class AlgebraicBigIntege
         DataBag values = (DataBag)input.get(0);
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
         BigInteger sofar = 
AlgebraicBigIntegerMathBase.getSeed(opProvider.getOp());

Modified: pig/trunk/src/org/apache/pig/builtin/AlgebraicByteArrayMathBase.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AlgebraicByteArrayMathBase.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AlgebraicByteArrayMathBase.java 
(original)
+++ pig/trunk/src/org/apache/pig/builtin/AlgebraicByteArrayMathBase.java Mon 
Jan 11 00:18:15 2016
@@ -67,7 +67,7 @@ public abstract class AlgebraicByteArray
         DataBag values = (DataBag)input.get(0);
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
         double sofar = AlgebraicByteArrayMathBase.getSeed(opProvider.getOp());

Modified: pig/trunk/src/org/apache/pig/builtin/AlgebraicDoubleMathBase.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AlgebraicDoubleMathBase.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AlgebraicDoubleMathBase.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/AlgebraicDoubleMathBase.java Mon Jan 
11 00:18:15 2016
@@ -64,7 +64,7 @@ public abstract class AlgebraicDoubleMat
         DataBag values = (DataBag)input.get(0);
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
         double sofar = AlgebraicDoubleMathBase.getSeed(opProvider.getOp());

Modified: pig/trunk/src/org/apache/pig/builtin/AlgebraicFloatMathBase.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AlgebraicFloatMathBase.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AlgebraicFloatMathBase.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/AlgebraicFloatMathBase.java Mon Jan 11 
00:18:15 2016
@@ -64,7 +64,7 @@ public abstract class AlgebraicFloatMath
         DataBag values = (DataBag)input.get(0);
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
         Float sofar = AlgebraicFloatMathBase.getSeed(opProvider.getOp());

Modified: pig/trunk/src/org/apache/pig/builtin/AlgebraicIntMathBase.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AlgebraicIntMathBase.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AlgebraicIntMathBase.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/AlgebraicIntMathBase.java Mon Jan 11 
00:18:15 2016
@@ -64,7 +64,7 @@ public abstract class AlgebraicIntMathBa
         DataBag values = (DataBag)input.get(0);
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
         int sofar = AlgebraicIntMathBase.getSeed(opProvider.getOp());

Modified: pig/trunk/src/org/apache/pig/builtin/AlgebraicLongMathBase.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/AlgebraicLongMathBase.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/AlgebraicLongMathBase.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/AlgebraicLongMathBase.java Mon Jan 11 
00:18:15 2016
@@ -64,7 +64,7 @@ public abstract class AlgebraicLongMathB
         DataBag values = (DataBag)input.get(0);
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
         Long sofar = AlgebraicLongMathBase.getSeed(opProvider.getOp());

Modified: pig/trunk/src/org/apache/pig/builtin/BigDecimalAvg.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/BigDecimalAvg.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/BigDecimalAvg.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/BigDecimalAvg.java Mon Jan 11 00:18:15 
2016
@@ -18,20 +18,20 @@
 package org.apache.pig.builtin;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.math.BigDecimal;
 import java.math.MathContext;
+import java.util.Iterator;
 
 import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
 import org.apache.pig.PigException;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
-import org.apache.pig.backend.executionengine.ExecException;
 
 
 /**
@@ -61,14 +61,17 @@ public class BigDecimalAvg extends EvalF
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -199,7 +202,7 @@ public class BigDecimalAvg extends EvalF
         DataBag values = (DataBag)input.get(0);
 
         // if we were handed an empty bag, return NULL
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 

Modified: pig/trunk/src/org/apache/pig/builtin/BigIntegerAvg.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/BigIntegerAvg.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/BigIntegerAvg.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/BigIntegerAvg.java Mon Jan 11 00:18:15 
2016
@@ -18,21 +18,21 @@
 package org.apache.pig.builtin;
 
 import java.io.IOException;
-import java.util.Iterator;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.math.MathContext;
+import java.util.Iterator;
 
 import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
 import org.apache.pig.PigException;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
-import org.apache.pig.backend.executionengine.ExecException;
 
 
 /**
@@ -62,14 +62,17 @@ public class BigIntegerAvg extends EvalF
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -201,7 +204,7 @@ public class BigIntegerAvg extends EvalF
         DataBag values = (DataBag)input.get(0);
 
         // if we were handed an empty bag, return NULL
-        if (values.size() == 0) {
+        if (values == null || values.size() == 0) {
             return null;
         }
 

Modified: pig/trunk/src/org/apache/pig/builtin/DateTimeMax.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/DateTimeMax.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/DateTimeMax.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/DateTimeMax.java Mon Jan 11 00:18:15 
2016
@@ -20,8 +20,6 @@ package org.apache.pig.builtin;
 import java.io.IOException;
 import java.util.Iterator;
 
-import org.joda.time.DateTime;
-
 import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
@@ -32,6 +30,7 @@ import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.joda.time.DateTime;
 
 /**
  * This method should never be used directly, use {@link MAX}.
@@ -47,14 +46,17 @@ public class DateTimeMax extends EvalFun
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -120,7 +122,7 @@ public class DateTimeMax extends EvalFun
 
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 
@@ -153,7 +155,7 @@ public class DateTimeMax extends EvalFun
 
     @Override
     public Schema outputSchema(Schema input) {
-        return new Schema(new Schema.FieldSchema(null, DataType.DATETIME)); 
+        return new Schema(new Schema.FieldSchema(null, DataType.DATETIME));
     }
 
 

Modified: pig/trunk/src/org/apache/pig/builtin/DateTimeMin.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/DateTimeMin.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/DateTimeMin.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/DateTimeMin.java Mon Jan 11 00:18:15 
2016
@@ -20,8 +20,6 @@ package org.apache.pig.builtin;
 import java.io.IOException;
 import java.util.Iterator;
 
-import org.joda.time.DateTime;
-
 import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
@@ -32,6 +30,7 @@ import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.joda.time.DateTime;
 
 /**
  * This method should never be used directly, use {@link MAX}.
@@ -47,14 +46,17 @@ public class DateTimeMin extends EvalFun
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -120,7 +122,7 @@ public class DateTimeMin extends EvalFun
 
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 

Modified: pig/trunk/src/org/apache/pig/builtin/DoubleAvg.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/DoubleAvg.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/DoubleAvg.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/DoubleAvg.java Mon Jan 11 00:18:15 2016
@@ -18,28 +18,25 @@
 package org.apache.pig.builtin;
 
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.Iterator;
 
 import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
-import org.apache.pig.FuncSpec;
 import org.apache.pig.PigException;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
-import org.apache.pig.impl.logicalLayer.FrontendException;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
-import org.apache.pig.backend.executionengine.ExecException;
 
 
 /**
  * This method should never be used directly, use {@link AVG}.
  */
 public class DoubleAvg extends EvalFunc<Double> implements Algebraic, 
Accumulator<Double> {
-    
+
     private static TupleFactory mTupleFactory = TupleFactory.getInstance();
 
     @Override
@@ -56,21 +53,24 @@ public class DoubleAvg extends EvalFunc<
             Double avg = null;
             if (count > 0)
                 avg = new Double(sum / count);
-    
+
             return avg;
         } catch (ExecException ee) {
             throw ee;
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -91,7 +91,7 @@ public class DoubleAvg extends EvalFunc<
                 t.set(0, d);
                 if (d != null){
                     t.set(1, 1L);
-                }else{    
+                } else {
                     t.set(1, 0L);
                 }
                 return t;
@@ -100,9 +100,9 @@ public class DoubleAvg extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
-                
+
         }
     }
 
@@ -117,7 +117,7 @@ public class DoubleAvg extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
        
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -145,7 +145,7 @@ public class DoubleAvg extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
        
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -166,7 +166,7 @@ public class DoubleAvg extends EvalFunc<
             Tuple t = it.next();
             Double d = (Double)t.get(0);
             // we count nulls in avg as contributing 0
-            // a departure from SQL for performance of 
+            // a departure from SQL for performance of
             // COUNT() which implemented by just inspecting
             // size of the bag
             if(d == null) {
@@ -200,9 +200,9 @@ public class DoubleAvg extends EvalFunc<
 
     static protected Double sum(Tuple input) throws ExecException, IOException 
{
         DataBag values = (DataBag)input.get(0);
-        
+
         // if we were handed an empty bag, return NULL
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 
@@ -228,17 +228,17 @@ public class DoubleAvg extends EvalFunc<
             return null;
         }
     }
-    
+
     @Override
     public Schema outputSchema(Schema input) {
-        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE)); 
+        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE));
     }
-    
+
     /* Accumulator interface */
-    
+
     private Double intermediateSum = null;
     private Double intermediateCount = null;
-    
+
     @Override
     public void accumulate(Tuple b) throws IOException {
         try {
@@ -251,7 +251,7 @@ public class DoubleAvg extends EvalFunc<
                 intermediateSum = 0.0;
                 intermediateCount = 0.0;
             }
-            
+
             double count = (Long)count(b);
 
             if (count > 0) {
@@ -263,9 +263,9 @@ public class DoubleAvg extends EvalFunc<
         } catch (Exception e) {
             int errCode = 2106;
             String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-            throw new ExecException(msg, errCode, PigException.BUG, e);        
   
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
-    }        
+    }
 
     @Override
     public void cleanup() {
@@ -280,5 +280,5 @@ public class DoubleAvg extends EvalFunc<
             avg = new Double(intermediateSum / intermediateCount);
         }
         return avg;
-    }    
+    }
 }

Modified: pig/trunk/src/org/apache/pig/builtin/FloatAvg.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/FloatAvg.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/FloatAvg.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/FloatAvg.java Mon Jan 11 00:18:15 2016
@@ -24,19 +24,19 @@ import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
 import org.apache.pig.PigException;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
-import org.apache.pig.backend.executionengine.ExecException;
 
 
 /**
  * This method should never be used directly, use {@link AVG}.
  */
 public class FloatAvg extends EvalFunc<Double> implements Algebraic, 
Accumulator<Double> {
-    
+
     private static TupleFactory mTupleFactory = TupleFactory.getInstance();
 
     @Override
@@ -53,21 +53,24 @@ public class FloatAvg extends EvalFunc<D
             Double avg = null;
             if (count > 0)
                 avg = new Double(sum / count);
-    
+
             return avg;
         } catch (ExecException ee) {
             throw ee;
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -96,9 +99,9 @@ public class FloatAvg extends EvalFunc<D
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
-                
+
         }
     }
 
@@ -113,7 +116,7 @@ public class FloatAvg extends EvalFunc<D
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -141,7 +144,7 @@ public class FloatAvg extends EvalFunc<D
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -162,7 +165,7 @@ public class FloatAvg extends EvalFunc<D
             Tuple t = it.next();
             Double d = (Double)t.get(0);
             // we count nulls in avg as contributing 0
-            // a departure from SQL for performance of 
+            // a departure from SQL for performance of
             // COUNT() which implemented by just inspecting
             // size of the bag
             if(d == null) {
@@ -199,7 +202,7 @@ public class FloatAvg extends EvalFunc<D
         DataBag values = (DataBag)input.get(0);
 
         // if we were handed an empty bag, return NULL
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 
@@ -225,17 +228,17 @@ public class FloatAvg extends EvalFunc<D
             return null;
         }
     }
-    
+
     @Override
     public Schema outputSchema(Schema input) {
-        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE)); 
+        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE));
     }
-    
+
     /* Accumulator interface */
 
     private Double intermediateSum = null;
     private Double intermediateCount = null;
-    
+
     @Override
     public void accumulate(Tuple b) throws IOException {
         try {
@@ -248,9 +251,9 @@ public class FloatAvg extends EvalFunc<D
                 intermediateSum = 0.0;
                 intermediateCount = 0.0;
             }
-            
+
             double count = (Long)count(b);
-            
+
             if (count > 0) {
                 intermediateCount += count;
                 intermediateSum += sum;
@@ -260,9 +263,9 @@ public class FloatAvg extends EvalFunc<D
         } catch (Exception e) {
             int errCode = 2106;
             String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-            throw new ExecException(msg, errCode, PigException.BUG, e);        
   
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
-    }        
+    }
 
     @Override
     public void cleanup() {
@@ -277,6 +280,6 @@ public class FloatAvg extends EvalFunc<D
             avg = new Double(intermediateSum / intermediateCount);
         }
         return avg;
-    }    
+    }
 
 }

Modified: pig/trunk/src/org/apache/pig/builtin/IntAvg.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/IntAvg.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/IntAvg.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/IntAvg.java Mon Jan 11 00:18:15 2016
@@ -24,19 +24,19 @@ import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
 import org.apache.pig.PigException;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
-import org.apache.pig.backend.executionengine.ExecException;
 
 
 /**
  * This method should never be used directly, use {@link AVG}.
  */
 public class IntAvg extends EvalFunc<Double> implements Algebraic, 
Accumulator<Double> {
-    
+
     private static TupleFactory mTupleFactory = TupleFactory.getInstance();
 
     @Override
@@ -53,21 +53,24 @@ public class IntAvg extends EvalFunc<Dou
             Double avg = null;
             if (count > 0)
                 avg = new Double(sum / count);
-    
+
             return avg;
         } catch (ExecException ee) {
             throw ee;
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -75,7 +78,7 @@ public class IntAvg extends EvalFunc<Dou
     static public class Initial extends EvalFunc<Tuple> {
         @Override
         public Tuple exec(Tuple input) throws IOException {
-            
+
             try {
                 Tuple t = mTupleFactory.newTuple(2);
                 // input is a bag with one tuple containing
@@ -97,9 +100,9 @@ public class IntAvg extends EvalFunc<Dou
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
-                
+
         }
     }
 
@@ -114,7 +117,7 @@ public class IntAvg extends EvalFunc<Dou
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -142,7 +145,7 @@ public class IntAvg extends EvalFunc<Dou
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -163,7 +166,7 @@ public class IntAvg extends EvalFunc<Dou
             Tuple t = it.next();
             Long l = (Long)t.get(0);
             // we count nulls in avg as contributing 0
-            // a departure from SQL for performance of 
+            // a departure from SQL for performance of
             // COUNT() which implemented by just inspecting
             // size of the bag
             if(l == null) {
@@ -200,7 +203,7 @@ public class IntAvg extends EvalFunc<Dou
         DataBag values = (DataBag)input.get(0);
 
         // if we were handed an empty bag, return NULL
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 
@@ -211,7 +214,7 @@ public class IntAvg extends EvalFunc<Dou
             try {
                 Integer i = (Integer)(t.get(0));
                 // we count nulls in avg as contributing 0
-                // a departure from SQL for performance of 
+                // a departure from SQL for performance of
                 // COUNT() which implemented by just inspecting
                 // size of the bag
                 if (i == null) continue;
@@ -230,17 +233,17 @@ public class IntAvg extends EvalFunc<Dou
             return null;
         }
     }
-    
+
     @Override
     public Schema outputSchema(Schema input) {
-        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE)); 
+        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE));
     }
 
     /* Accumulator interface */
 
     private Long intermediateSum = null;
     private Double intermediateCount = null;
-    
+
     @Override
     public void accumulate(Tuple b) throws IOException {
         try {
@@ -253,7 +256,7 @@ public class IntAvg extends EvalFunc<Dou
                 intermediateSum = 0L;
                 intermediateCount = 0.0;
             }
-            
+
             double count = (Long)count(b);
 
             if (count > 0) {
@@ -265,9 +268,9 @@ public class IntAvg extends EvalFunc<Dou
         } catch (Exception e) {
             int errCode = 2106;
             String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-            throw new ExecException(msg, errCode, PigException.BUG, e);        
   
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
-    }        
+    }
 
     @Override
     public void cleanup() {

Modified: pig/trunk/src/org/apache/pig/builtin/LongAvg.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/LongAvg.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/LongAvg.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/LongAvg.java Mon Jan 11 00:18:15 2016
@@ -24,19 +24,19 @@ import org.apache.pig.Accumulator;
 import org.apache.pig.Algebraic;
 import org.apache.pig.EvalFunc;
 import org.apache.pig.PigException;
+import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
-import org.apache.pig.backend.executionengine.ExecException;
 
 
 /**
  * This method should never be used directly, use {@link AVG}.
  */
 public class LongAvg extends EvalFunc<Double> implements Algebraic, 
Accumulator<Double> {
-    
+
     private static TupleFactory mTupleFactory = TupleFactory.getInstance();
 
     @Override
@@ -53,21 +53,24 @@ public class LongAvg extends EvalFunc<Do
             Double avg = null;
             if (count > 0)
                 avg = new Double(sum / count);
-    
+
             return avg;
         } catch (ExecException ee) {
             throw ee;
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -96,9 +99,9 @@ public class LongAvg extends EvalFunc<Do
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
-                
+
         }
     }
 
@@ -113,7 +116,7 @@ public class LongAvg extends EvalFunc<Do
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -141,7 +144,7 @@ public class LongAvg extends EvalFunc<Do
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -162,7 +165,7 @@ public class LongAvg extends EvalFunc<Do
             Tuple t = it.next();
             Long l = (Long)t.get(0);
             // we count nulls in avg as contributing 0
-            // a departure from SQL for performance of 
+            // a departure from SQL for performance of
             // COUNT() which implemented by just inspecting
             // size of the bag
             if(l == null) {
@@ -199,7 +202,7 @@ public class LongAvg extends EvalFunc<Do
         DataBag values = (DataBag)input.get(0);
 
         // if we were handed an empty bag, return NULL
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 
@@ -225,17 +228,17 @@ public class LongAvg extends EvalFunc<Do
             return null;
         }
     }
-    
+
     @Override
     public Schema outputSchema(Schema input) {
-        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE)); 
+        return new Schema(new Schema.FieldSchema(null, DataType.DOUBLE));
     }
-    
+
     /* Accumulator interface */
-   
+
     private Long intermediateSum = null;
     private Double intermediateCount = null;
-    
+
     @Override
     public void accumulate(Tuple b) throws IOException {
         try {
@@ -248,7 +251,7 @@ public class LongAvg extends EvalFunc<Do
                 intermediateSum = 0L;
                 intermediateCount = 0.0;
             }
-            
+
             double count = (Long)count(b);
 
             if (count > 0) {
@@ -260,9 +263,9 @@ public class LongAvg extends EvalFunc<Do
         } catch (Exception e) {
             int errCode = 2106;
             String msg = "Error while computing average in " + 
this.getClass().getSimpleName();
-            throw new ExecException(msg, errCode, PigException.BUG, e);        
   
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
-    }        
+    }
 
     @Override
     public void cleanup() {

Modified: pig/trunk/src/org/apache/pig/builtin/StringMax.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/StringMax.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/StringMax.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/StringMax.java Mon Jan 11 00:18:15 2016
@@ -45,14 +45,17 @@ public class StringMax extends EvalFunc<
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -77,7 +80,7 @@ public class StringMax extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing max in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -94,7 +97,7 @@ public class StringMax extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing max in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -108,17 +111,17 @@ public class StringMax extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing max in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
 
     static protected String max(Tuple input) throws ExecException {
         DataBag values = (DataBag)input.get(0);
-        
+
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 
@@ -129,7 +132,7 @@ public class StringMax extends EvalFunc<
             Tuple t = it.next();
             curMax = (String)(t.get(0));
         }
-        
+
         for (; it.hasNext();) {
             Tuple t = it.next();
             try {
@@ -138,26 +141,26 @@ public class StringMax extends EvalFunc<
                 if( s.compareTo(curMax) > 0) {
                     curMax = s;
                 }
-                
+
             } catch (RuntimeException exp) {
                 int errCode = 2103;
                 String msg = "Problem while computing max of strings.";
                 throw new ExecException(msg, errCode, PigException.BUG, exp);
             }
         }
-    
+
         return curMax;
     }
 
     @Override
     public Schema outputSchema(Schema input) {
-        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY)); 
+        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY));
     }
 
 
     /* accumulator interface */
     private String intermediateMax = null;
-    
+
     @Override
     public void accumulate(Tuple b) throws IOException {
         try {
@@ -168,14 +171,14 @@ public class StringMax extends EvalFunc<
             // check if it lexicographically follows curMax
             if (intermediateMax == null || intermediateMax.compareTo(curMax) < 
0) {
                 intermediateMax = curMax;
-            }            
+            }
 
         } catch (ExecException ee) {
             throw ee;
         } catch (Exception e) {
             int errCode = 2106;
             String msg = "Error while computing max in " + 
this.getClass().getSimpleName();
-            throw new ExecException(msg, errCode, PigException.BUG, e);        
   
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
     }
 

Modified: pig/trunk/src/org/apache/pig/builtin/StringMin.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/StringMin.java?rev=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/StringMin.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/StringMin.java Mon Jan 11 00:18:15 2016
@@ -46,14 +46,17 @@ public class StringMin extends EvalFunc<
         }
     }
 
+    @Override
     public String getInitial() {
         return Initial.class.getName();
     }
 
+    @Override
     public String getIntermed() {
         return Intermediate.class.getName();
     }
 
+    @Override
     public String getFinal() {
         return Final.class.getName();
     }
@@ -78,7 +81,7 @@ public class StringMin extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing min in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -95,7 +98,7 @@ public class StringMin extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing min in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
@@ -109,17 +112,17 @@ public class StringMin extends EvalFunc<
             } catch (Exception e) {
                 int errCode = 2106;
                 String msg = "Error while computing min in " + 
this.getClass().getSimpleName();
-                throw new ExecException(msg, errCode, PigException.BUG, e);    
       
+                throw new ExecException(msg, errCode, PigException.BUG, e);
             }
         }
     }
 
     static protected String min(Tuple input) throws ExecException {
         DataBag values = (DataBag)input.get(0);
-        
+
         // if we were handed an empty bag, return NULL
         // this is in compliance with SQL standard
-        if(values.size() == 0) {
+        if(values == null || values.size() == 0) {
             return null;
         }
 
@@ -130,7 +133,7 @@ public class StringMin extends EvalFunc<
             Tuple t = it.next();
             curMin = (String)(t.get(0));
         }
-        
+
         for (; it.hasNext();) {
             Tuple t = it.next();
             try {
@@ -139,25 +142,25 @@ public class StringMin extends EvalFunc<
                 if( s.compareTo(curMin) < 0) {
                     curMin = s;
                 }
-                
+
             } catch (RuntimeException exp) {
                 int errCode = 2103;
                 String msg = "Problem while computing min of strings.";
                 throw new ExecException(msg, errCode, PigException.BUG, exp);
             }
         }
-    
+
         return curMin;
     }
 
     @Override
     public Schema outputSchema(Schema input) {
-        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY)); 
+        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY));
     }
-    
+
     /* accumulator interface */
     private String intermediateMin = null;
-    
+
     @Override
     public void accumulate(Tuple b) throws IOException {
         try {
@@ -168,14 +171,14 @@ public class StringMin extends EvalFunc<
             // check if it lexicographically follows curMax
             if (intermediateMin == null || intermediateMin.compareTo(curMin) > 
0) {
                 intermediateMin = curMin;
-            }            
+            }
 
         } catch (ExecException ee) {
             throw ee;
         } catch (Exception e) {
             int errCode = 2106;
             String msg = "Error while computing max in " + 
this.getClass().getSimpleName();
-            throw new ExecException(msg, errCode, PigException.BUG, e);        
   
+            throw new ExecException(msg, errCode, PigException.BUG, e);
         }
     }
 

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=1723972&r1=1723971&r2=1723972&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestBuiltin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestBuiltin.java Mon Jan 11 00:18:15 2016
@@ -143,6 +143,8 @@ public class TestBuiltin {
     private TupleFactory tupleFactory = TupleFactory.getInstance();
     private BagFactory bagFactory = DefaultBagFactory.getInstance();
 
+    private static Tuple NULL_INPUT_TUPLE;
+
     // some inputs
     private static Integer[] intInput = { 3, 1, 2, 4, 5, 7, null, 6, 8, 9, 10 
};
     private static Long[] intAsLong = { 3L, 1L, 2L, 4L, 5L, 7L, null, 6L, 8L, 
9L, 10L };
@@ -222,6 +224,9 @@ public class TestBuiltin {
         // first set up EvalFuncMap and expectedMap
         setupEvalFuncMap();
 
+        NULL_INPUT_TUPLE = TupleFactory.getInstance().newTuple(1);
+        NULL_INPUT_TUPLE.set(0, null);
+
         expectedMap.put("SUM", new Double(55));
         expectedMap.put("DoubleSum", new Double(170.567391834593));
         expectedMap.put("IntSum", new Long(55));
@@ -955,6 +960,9 @@ public class TestBuiltin {
             } else {
                 assertEquals(msg, (Double)output, 
(Double)getExpected(avgTypes[k]), 0.00001);
             }
+
+            // Check null input
+            assertNull(avg.exec(NULL_INPUT_TUPLE));
         }
     }
 
@@ -1423,6 +1431,9 @@ public class TestBuiltin {
             else {
                 assertEquals(msg, (Double)output, 
(Double)getExpected(sumTypes[k]), 0.00001);
             }
+
+            // Check null input
+            assertNull(sum.exec(NULL_INPUT_TUPLE));
         }
     }
 
@@ -1488,6 +1499,9 @@ public class TestBuiltin {
             String msg = "[Testing " + minTypes[k] + " on input type: " + 
getInputType(minTypes[k]) + " ( (output) " +
                            output + " == " + getExpected(minTypes[k]) + " 
(expected) )]";
             assertForInputType(inputType, msg, getExpected(minTypes[k]), 
output);
+
+            // Check null input
+            assertNull(min.exec(NULL_INPUT_TUPLE));
         }
     }
 
@@ -1554,6 +1568,9 @@ public class TestBuiltin {
             String msg = "[Testing " + maxTypes[k] + " on input type: " + 
getInputType(maxTypes[k]) + " ( (output) " +
                            output + " == " + getExpected(maxTypes[k]) + " 
(expected) )]";
             assertForInputType(inputType, msg, getExpected(maxTypes[k]), 
output);
+
+            // Check null input
+            assertNull(max.exec(NULL_INPUT_TUPLE));
         }
     }
 
@@ -3223,6 +3240,6 @@ public class TestBuiltin {
         pigServer.registerQuery("B = foreach A generate TOMAP(a);");
         s = pigServer.dumpSchema("B");
         Assert.assertEquals(s.toString(), "{map[]}");
-        
+
     }
 }


Reply via email to