pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1605662 - in /pig/trunk: CHANGES.txt src/docs/src/documentation/content/xdocs/func.xml src/org/apache/pig/builtin/SPRINTF.java test/org/apache/pig/test/TestBuiltin.java
Date Thu, 26 Jun 2014 04:23:48 GMT
Author: daijy
Date: Thu Jun 26 04:23:48 2014
New Revision: 1605662

URL: http://svn.apache.org/r1605662
Log:
PIG-4038: SPRINTF should return NULL on any NULL input

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/docs/src/documentation/content/xdocs/func.xml
    pig/trunk/src/org/apache/pig/builtin/SPRINTF.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=1605662&r1=1605661&r2=1605662&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Thu Jun 26 04:23:48 2014
@@ -42,6 +42,8 @@ OPTIMIZATIONS
  
 BUG FIXES
 
+PIG-4038: SPRINTF should return NULL on any NULL input (mrflip via daijy)
+
 PIG-4025: TestLoadFuncWrapper, TestLoadFuncMetaDataWrapper,TestStoreFuncWrapper
  and TestStoreFuncMetadataWrapper fail on IBM JDK (ahireanup via daijy)
 

Modified: pig/trunk/src/docs/src/documentation/content/xdocs/func.xml
URL: http://svn.apache.org/viewvc/pig/trunk/src/docs/src/documentation/content/xdocs/func.xml?rev=1605662&r1=1605661&r2=1605662&view=diff
==============================================================================
--- pig/trunk/src/docs/src/documentation/content/xdocs/func.xml (original)
+++ pig/trunk/src/docs/src/documentation/content/xdocs/func.xml Thu Jun 26 04:23:48 2014
@@ -4201,6 +4201,17 @@ Use the RTRIM function to remove trailin
       <td><p><code>' 1234567| 1234567|yay     '</code></p></td>
       <td><p>Format strings with %s, integers with %d. Types are converted for
you where reasonable (here, int -&gt; string).</p></td></tr>
 
+
+      <tr><td><p>(null value)</p></td>
+      <td><p><code>1234567</code></p></td>      <td><p><code>1234567</code></p></td>
   <td><p><code>'yay'</code></p></td>
+      <td><p>(null value)</p></td>
+      <td><p>Returns null (no error or warning) with a null format string.</p></td></tr>
+
+      <tr><td><p><code>'%8s|%8d|%-8s'</code></p></td>
+      <td><p><code>1234567</code></p></td>      <td><p>(null
value)</p></td>    <td><p><code>'yay'</code></p></td>
+      <td><p>(null value)</p></td>
+      <td><p>Returns null (no error or warning) if any single argument is null.</p></td></tr>
+
       <tr><td><p><code>'%8.3f|%6x'</code></p></td>
       <td><p><code>123.14159</code></p></td>    <td><p><code>665568</code></p></td>
    <td><p><code></code></p></td>
       <td><p><code>' 123.142| a27e0'</code></p></td>

Modified: pig/trunk/src/org/apache/pig/builtin/SPRINTF.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/SPRINTF.java?rev=1605662&r1=1605661&r2=1605662&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/SPRINTF.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/SPRINTF.java Thu Jun 26 04:23:48 2014
@@ -48,11 +48,13 @@ public class SPRINTF extends EvalFunc<St
         Formatter     formatter = new Formatter(sb);
         try{
             if (input == null || input.size() == 0) return null;
+            if (input.get(0) == null){ return null; }
 
             String   fmt  = String.valueOf(input.get(0));
             Object[] args = new Object[input.size()-1];
             for (int i = 1; i < input.size(); i++) {
                 args[i-1] =  input.get(i);
+                if (args[i-1] == null){ return null; }
             }
 
             formatter.format(fmt, args);

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=1605662&r1=1605661&r2=1605662&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestBuiltin.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestBuiltin.java Thu Jun 26 04:23:48 2014
@@ -2465,6 +2465,15 @@ public class TestBuiltin {
         res = sprinter.exec(ts);
         assertEquals(exp, res);
         //
+        // Returns null if any input is null
+        ts.set(3, null);
+        res = sprinter.exec(ts);
+        assertNull(res);
+        ts.set(3, ff);
+        ts.set(0, null);
+        res = sprinter.exec(ts);
+        assertNull(res);
+        //
         // Works with just one arg
         ts = TupleFactory.getInstance().newTuple(1);
         ts.set(0, "meep!");



Mime
View raw message