You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by sm...@apache.org on 2009/02/23 22:15:07 UTC

svn commit: r747139 - in /hadoop/pig/trunk: CHANGES.txt src/org/apache/pig/builtin/Utf8StorageConverter.java test/org/apache/pig/test/TestConversions.java

Author: sms
Date: Mon Feb 23 21:15:05 2009
New Revision: 747139

URL: http://svn.apache.org/viewvc?rev=747139&view=rev
Log:
PIG-658: Data type long : When 'L' or 'l' is included with data (123L or 123l) load produces null value. Also the case with Float (thejas via sms)

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestConversions.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=747139&r1=747138&r2=747139&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Mon Feb 23 21:15:05 2009
@@ -426,3 +426,7 @@
 
     PIG-545: PERFORMANCE: Sampler for order bys does not produce a good
     distribution (pradeepkth)
+
+    PIG-658: Data type long : When 'L' or 'l' is included with data 
+    (123L or 123l) load produces null value. Also the case with Float (thejas
+    via sms)

Modified: hadoop/pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java?rev=747139&r1=747138&r2=747139&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java Mon Feb 23 21:15:05 2009
@@ -107,8 +107,17 @@
     public Float bytesToFloat(byte[] b) throws IOException {
         if(b == null)
             return null;
+        String s;
+        if(b.length > 0 && 
+           (b[b.length - 1] == 'F' || b[b.length - 1] == 'f') ){
+            s = new String(b, 0, b.length - 1);
+        } 
+        else {
+            s = new String(b);
+        }
+        
         try {
-            return Float.valueOf(new String(b));
+            return Float.valueOf(s);
         } catch (NumberFormatException nfe) {
             mLog.warn("Unable to interpret value " + b + " in field being " +
                     "converted to float, caught NumberFormatException <" +
@@ -148,7 +157,16 @@
     public Long bytesToLong(byte[] b) throws IOException {
         if(b == null)
             return null;
-        String s = new String(b);
+
+        String s;
+        if(b.length > 0  &&  
+           (b[b.length - 1] == 'L' || b[b.length - 1] == 'l') ){
+            s = new String(b, 0, b.length - 1);
+        } 
+        else {
+            s = new String(b);
+        }
+
         try {
             return Long.valueOf(s);
         } catch (NumberFormatException nfe) {

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestConversions.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestConversions.java?rev=747139&r1=747138&r2=747139&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestConversions.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestConversions.java Mon Feb 23 21:15:05 2009
@@ -70,8 +70,12 @@
     public  void testBytesToFloat() throws IOException
     {
         // valid floats
-        String[] a = {"1", "-2.345",  "12.12334567", "1.02e-2",".23344", "23.1234567897", ""};
-        Float[] f = {1f, -2.345f,  12.12334567f, 1.02e-2f,.23344f, 23.1234567f}; // last case is a truncation case
+        String[] a = {"1", "-2.345",  "12.12334567", "1.02e-2",".23344",
+		      "23.1234567897", "12312.33f", "002312.33F", "1.02e-2f", ""};
+
+        Float[] f = {1f, -2.345f,  12.12334567f, 1.02e-2f,.23344f, 23.1234567f, // 23.1234567f is a truncation case
+		     12312.33f, 2312.33f, 1.02e-2f }; 
+
         for (int j = 0; j < f.length; j++) {
             byte[] b = a[j].getBytes();            
             assertEquals(f[j], ps.bytesToFloat(b));
@@ -112,8 +116,10 @@
     public  void testBytesToLong() throws IOException
     {
         // valid Longs
-        String[] a = {"1", "-2345",  "123456789012345678", "1.1", "-23.45", ""};
-        Long[] la = {1L, -2345L, 123456789012345678L, 1L, -23L};
+        String[] a = {"1", "-2345",  "123456789012345678", "1.1", "-23.45",
+		      "21345345l", "3422342L", ""};
+        Long[] la = {1L, -2345L, 123456789012345678L, 1L, -23L, 
+		     21345345L, 3422342L};
         
         for (int i = 0; i < la.length; i++) {
             byte[] b = a[i].getBytes();