You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2012/11/07 21:17:06 UTC

svn commit: r1406790 - in /hbase/branches/0.89-fb: pom.xml src/main/java/org/apache/hadoop/hbase/client/Get.java src/main/java/org/apache/hadoop/hbase/client/Scan.java src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Author: liyin
Date: Wed Nov  7 20:17:05 2012
New Revision: 1406790

URL: http://svn.apache.org/viewvc?rev=1406790&view=rev
Log:
[HBASE-7106] Fix the NPE in unit tests for JDK7

Author: liyintang

Summary:
In JDK7, it will throw out NPE if put a NULL into a TreeSet. And in the unit tests, user can add a NULL as qualifier into the family map for GET or SCAN.
So we shall do the followings:

1) Make sure the semantics of NULL column qualifier is equal to that of the EMPYT_BYTE_ARRAY column qualifier.

2) An easy fix is to use the EMPYT_BYTE_ARRAY qualifier to replace NULL qualifier in the family map for the GET or SCAN objects, and everything else shall be backward compatible.

3) Add a jdk option in the pom.xml (Assuming user installed the fb packaged jdk)
eg: mvn test -Dtest=TestFromClientSide -Pjdk7

Test Plan: Running unit tests

Reviewers: kannan

Reviewed By: kannan

CC: hbase-eng@

Differential Revision: https://phabricator.fb.com/D621313

Modified:
    hbase/branches/0.89-fb/pom.xml
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Get.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Scan.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Modified: hbase/branches/0.89-fb/pom.xml
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/pom.xml?rev=1406790&r1=1406789&r2=1406790&view=diff
==============================================================================
--- hbase/branches/0.89-fb/pom.xml (original)
+++ hbase/branches/0.89-fb/pom.xml Wed Nov  7 20:17:05 2012
@@ -139,7 +139,37 @@
       <organizationUrl>http://www.cloudera.com</organizationUrl>
     </developer>
   </developers>
-
+  
+  <profiles>
+    <profile>
+      <id>default_jdk</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <properties>
+        <jdk>${env.JAVA_HOME}</jdk>
+      </properties>
+    </profile>
+    <profile>
+      <id>jdk6</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <properties>
+        <jdk>/usr/local/jdk-6u14-64</jdk>
+      </properties>
+    </profile>
+    <profile>
+      <id>jdk7</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <properties>
+        <jdk>/usr/local/jdk-7u6-64</jdk>
+      </properties>
+    </profile>
+  </profiles>
+  
   <repositories>
     <repository>
       <id>nicolas fb releases</id>

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Get.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Get.java?rev=1406790&r1=1406789&r2=1406790&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Get.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Get.java Wed Nov  7 20:17:05 2012
@@ -20,6 +20,7 @@
 package org.apache.hadoop.hbase.client;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.filter.Filter;
 import org.apache.hadoop.hbase.io.TimeRange;
@@ -132,10 +133,14 @@ public class Get extends OperationWithAt
    */
   public Get addColumn(byte [] family, byte [] qualifier) {
     NavigableSet<byte []> set = familyMap.get(family);
-    if(set == null) {
+    if (set == null) {
       set = new TreeSet<byte []>(Bytes.BYTES_COMPARATOR);
     }
-    set.add(qualifier);
+    if (qualifier == null) {
+      set.add(HConstants.EMPTY_BYTE_ARRAY);
+    } else {
+      set.add(qualifier);
+    }
     familyMap.put(family, set);
     return this;
   }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Scan.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Scan.java?rev=1406790&r1=1406789&r2=1406790&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Scan.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/client/Scan.java Wed Nov  7 20:17:05 2012
@@ -204,10 +204,15 @@ public class Scan extends Operation impl
    */
   public Scan addColumn(byte [] family, byte [] qualifier) {
     NavigableSet<byte []> set = familyMap.get(family);
-    if(set == null) {
+    if (set == null) {
       set = new TreeSet<byte []>(Bytes.BYTES_COMPARATOR);
     }
-    set.add(qualifier);
+    
+    if (qualifier == null) {
+      set.add(HConstants.EMPTY_BYTE_ARRAY);
+    } else {
+      set.add(qualifier);
+    }
     familyMap.put(family, set);
 
     return this;

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1406790&r1=1406789&r2=1406790&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Wed Nov  7 20:17:05 2012
@@ -130,6 +130,50 @@ public class TestFromClientSide {
   }
 
   @Test
+  public void testEmptyColumn() throws Exception {
+    byte [] TABLE = Bytes.toBytes("testEmptyColumn");
+    byte [][] FAMILIES = new byte[][] {FAMILY};
+    byte [] r1 = Bytes.toBytes("r1");
+    byte [] r2 = Bytes.toBytes("r12");
+    byte[] value =  Bytes.toBytes("v");
+    Result result1, result2;
+    
+    HTable ht = TEST_UTIL.createTable(TABLE, FAMILIES);
+    Put put = new Put(r1);
+    put.add(FAMILY, null, value);
+    ht.put(put);
+   
+    Get g1 = new Get(r1);
+    g1.addColumn(FAMILY, null);
+    result1 = ht.get(g1);
+    
+    Get g2 = new Get(r1);
+    g2.addColumn(FAMILY, HConstants.EMPTY_BYTE_ARRAY);
+    result2 = ht.get(g2);
+    
+    assertEquals(result1.getBytes(), result2.getBytes());
+    assertEquals(1, result2.raw().length);
+    assertEquals(result1.raw().length, result2.raw().length);
+    
+    put = new Put(r2);
+    put.add(FAMILY, HConstants.EMPTY_BYTE_ARRAY, value);
+    ht.put(put);
+    ht.flushCommits();
+    
+    g1 = new Get(r2);
+    g1.addColumn(FAMILY, null);
+    result1 = ht.get(g1);
+    
+    g2 = new Get(r2);
+    g2.addColumn(FAMILY, HConstants.EMPTY_BYTE_ARRAY);
+    result2 = ht.get(g2);
+    
+    assertEquals(result1.getBytes(), result2.getBytes());
+    assertEquals(1, result2.raw().length);
+    assertEquals(result1.raw().length, result2.raw().length);
+  }
+  
+  @Test
   public void testFlashBackTime() throws Exception {
     byte[] TABLE = Bytes.toBytes("testFlashBackTime");
     HColumnDescriptor[] expected = new HColumnDescriptor[10];