Author: zjffdu
Date: Mon Sep  6 02:05:25 2010
New Revision: 992926

URL: http://svn.apache.org/viewvc?rev=992926&view=rev
Log:
PIG-1596: NPE's thrown when attempting to load hbase columns containing null 
values (zjffdu)

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/hbase/HBaseStorage.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestHBaseStorage.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=992926&r1=992925&r2=992926&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Mon Sep  6 02:05:25 2010
@@ -197,6 +197,8 @@ PIG-1309: Map-side Cogroup (ashutoshc)
 
 BUG FIXES
 
+PIG-1596: NPE's thrown when attempting to load hbase columns containing null 
values (zjffdu)
+
 PIG-1597: Development snapshot jar no longer picked up by bin/pig (dvryaboy)
 
 PIG-1599: pig gives generic message for few cases (nrai via rding)

Modified: 
hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/hbase/HBaseStorage.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/hbase/HBaseStorage.java?rev=992926&r1=992925&r2=992926&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/hbase/HBaseStorage.java 
(original)
+++ hadoop/pig/trunk/src/org/apache/pig/backend/hadoop/hbase/HBaseStorage.java 
Mon Sep  6 02:05:25 2010
@@ -247,7 +247,11 @@ public class HBaseStorage extends LoadFu
                     startIndex++;
                 }
                 for (int i=0;i<columnList_.size();++i){
-                    tuple.set(i+startIndex, new 
DataByteArray(result.getValue(columnList_.get(i))));
+                       byte[] cell=result.getValue(columnList_.get(i));
+                       if (cell!=null)
+                           tuple.set(i+startIndex, new DataByteArray(cell));
+                       else
+                           tuple.set(i+startIndex, null);
                 }
                 return tuple;
             }

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestHBaseStorage.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestHBaseStorage.java?rev=992926&r1=992925&r2=992926&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestHBaseStorage.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestHBaseStorage.java Mon Sep  6 
02:05:25 2010
@@ -171,8 +171,8 @@ public class TestHBaseStorage {
                prepareTable(TESTTABLE_1, true, DataFormat.UTF8PlainText);
                pig.registerQuery("a = load 'hbase://" + TESTTABLE_1 + "' using 
"
                                + 
"org.apache.pig.backend.hadoop.hbase.HBaseStorage('"
-                               + TESTCOLUMN_A + " " + TESTCOLUMN_B + " " + 
TESTCOLUMN_C
-                               + "') as (col_a, col_b, col_c);");
+                               + TESTCOLUMN_A + " " + TESTCOLUMN_B + " " + 
TESTCOLUMN_C +" pig:col_d"
+                               + "') as (col_a, col_b, col_c, col_d);");
                Iterator<Tuple> it = pig.openIterator("a");
                int count = 0;
                LOG.info("LoadFromHBase Starting");
@@ -182,10 +182,11 @@ public class TestHBaseStorage {
                        String col_a = ((DataByteArray) t.get(0)).toString();
                        String col_b = ((DataByteArray) t.get(1)).toString();
                        String col_c = ((DataByteArray) t.get(2)).toString();
-
+                       Object col_d = t.get(3);       // empty cell
                        Assert.assertEquals(count, Integer.parseInt(col_a));
                        Assert.assertEquals(count + 0.0, 
Double.parseDouble(col_b), 1e-6);
                        Assert.assertEquals("Text_" + count, col_c);
+                       Assert.assertNull(col_d);
                        count++;
                }
                Assert.assertEquals(TEST_ROW_COUNT, count);


Reply via email to