Author: thejas
Date: Wed Apr  7 01:32:00 2010
New Revision: 931398

URL: http://svn.apache.org/viewvc?rev=931398&view=rev
Log:
PIG-1352: piggybank UPPER udf throws exception if argument is null

Modified:
    hadoop/pig/trunk/CHANGES.txt
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=931398&r1=931397&r2=931398&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Wed Apr  7 01:32:00 2010
@@ -42,6 +42,8 @@ PIG-1313: PigServer leaks memory over ti
 PIG-1346: In unit tests Util.executeShellCommand relies on java commands being
 in the path and does not consider JAVA_HOME (pradeepkth)
 
+PIG-1352: piggybank UPPER udf throws exception if argument is null
+
 Release 0.7.0 - Unreleased
 
 INCOMPATIBLE CHANGES

Modified: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java?rev=931398&r1=931397&r2=931398&view=diff
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
 (original)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
 Wed Apr  7 01:32:00 2010
@@ -48,18 +48,23 @@ public class UPPER extends EvalFunc<Stri
      * @exception IOException
      */
     public String exec(Tuple input) throws IOException {
-        if (input == null || input.size() == 0)
+        if (input == null || input.size() == 0 || input.get(0) == null)
             return null;
 
         String str = null;
         try {
             str = (String)input.get(0);
-        } catch (ClassCastException e) {
+            return str.toUpperCase();
+        }
+        catch (ClassCastException e) {
             warn("unable to cast input "+input.get(0)+" of class "+
                     input.get(0).getClass()+" to String", 
PigWarning.UDF_WARNING_1);
             return null;
         }
-        return str.toUpperCase();
+        catch(Exception e){
+            warn("Error processing input "+input.get(0), 
PigWarning.UDF_WARNING_1);
+            return null;
+        }
     }
 
     /**

Modified: 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java?rev=931398&r1=931397&r2=931398&view=diff
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java
 (original)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java
 Wed Apr  7 01:32:00 2010
@@ -50,7 +50,11 @@ public class TestEvalString extends Test
 
         String output = func.exec(input);
         assertTrue(output.equals(expected));
-
+        
+        String in2 = null;
+        Tuple input2 = DefaultTupleFactory.getInstance().newTuple(in2);
+        assertEquals("upper null value",null, func.exec(input2));
+        
         // test schema creation
 
         // FIXME


Reply via email to