hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r909109 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java src/test/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java
Date Thu, 11 Feb 2010 19:05:02 GMT
Author: stack
Date: Thu Feb 11 19:04:59 2010
New Revision: 909109

URL: http://svn.apache.org/viewvc?rev=909109&view=rev
Log:
HBASE-2209 Support of List [ ] in HBaseOutputWritable for serialization

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java
    hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=909109&r1=909108&r2=909109&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Feb 11 19:04:59 2010
@@ -355,6 +355,8 @@
                (Ferdy via Stack)
    HBASE-2189  HCM trashes meta cache even when not needed
    HBASE-2190  HRS should report to master when HMsg are available
+   HBASE-2209  Support of List [ ] in HBaseOutputWritable for serialization
+               (Kay Kay via Stack)
 
   NEW FEATURES
    HBASE-1961  HBase EC2 scripts

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java?rev=909109&r1=909108&r2=909109&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java Thu Feb
11 19:04:59 2010
@@ -22,7 +22,11 @@
 import java.io.DataOutput;
 import java.io.IOException;
 import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -156,6 +160,9 @@
     addToMap(HLog.Entry.class, code++);
     addToMap(HLog.Entry[].class, code++);
     addToMap(HLogKey.class, code++);
+    
+    // List 
+    addToMap(List.class, code++);
   }
   
   private Class<?> declaredClass;
@@ -248,6 +255,11 @@
   static void writeClassCode(final DataOutput out, final Class<?> c)
   throws IOException {
     Byte code = CLASS_TO_CODE.get(c);
+    if (code == null ) {
+      if ( List.class.isAssignableFrom(c)) {
+        code = CLASS_TO_CODE.get(List.class);
+      }
+    }
     if (code == null) {
       LOG.error("Unsupported type " + c);
       StackTraceElement[] els = new Exception().getStackTrace();
@@ -299,6 +311,14 @@
                     declClass.getComponentType(), conf);
         }
       }
+    } else if (List.class.isAssignableFrom(declClass)) {
+      List list = (List)instanceObj;
+      int length = list.size();
+      out.writeInt(length);
+      for (int i = 0; i < length; i++) {
+        writeObject(out, list.get(i),
+                  list.get(i).getClass(), conf);
+      }
     } else if (declClass == String.class) {   // String
       Text.writeString(out, (String)instanceObj);
     } else if (declClass.isPrimitive()) {     // primitive type
@@ -402,6 +422,12 @@
           Array.set(instance, i, readObject(in, conf));
         }
       }
+    } else if (List.class.isAssignableFrom(declaredClass)) {              // List
+      int length = in.readInt();
+      instance = new ArrayList(length);
+      for (int i = 0; i < length; i++) {
+        ((ArrayList)instance).add(readObject(in, conf));
+      }
     } else if (declaredClass == String.class) {        // String
       instance = Text.readString(in);
     } else if (declaredClass.isEnum()) {         // enum

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java?rev=909109&r1=909108&r2=909109&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java Thu
Feb 11 19:04:59 2010
@@ -73,7 +73,8 @@
    * <li>Version 19: Added getClusterStatus().</li>
    * <li>Version 20: Backed Transaction HBase out of HBase core.</li>
    * <li>Version 21: HBASE-1665.</li>
+   * <li>Version 22: HBASE-2209. Added List support to RPC</li>
    * </ul>
    */
-  public static final long versionID = 21L;
+  public static final long versionID = 22L;
 }

Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java?rev=909109&r1=909108&r2=909109&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/io/TestHbaseObjectWritable.java Thu
Feb 11 19:04:59 2010
@@ -25,6 +25,8 @@
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -33,6 +35,7 @@
 import org.apache.hadoop.hbase.filter.PrefixFilter;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.WritableComparator;
+import org.junit.Assert;
 
 public class TestHbaseObjectWritable extends TestCase {
 
@@ -74,6 +77,22 @@
     // Do 'known' Writable type.
     obj = doType(conf, new Text(""), Text.class);
     assertTrue(obj instanceof Text);
+    //List.class
+    List<String> list = new ArrayList<String>();
+    list.add("hello");
+    list.add("world");
+    list.add("universe");
+    obj = doType(conf, list, List.class);
+    assertTrue(obj instanceof List);
+    Assert.assertArrayEquals(list.toArray(), ((List)obj).toArray() );
+    //ArrayList.class
+    ArrayList<String> arr = new ArrayList<String>();
+    arr.add("hello");
+    arr.add("world");
+    arr.add("universe");
+    obj = doType(conf,  arr, ArrayList.class);
+    assertTrue(obj instanceof ArrayList);
+    Assert.assertArrayEquals(list.toArray(), ((ArrayList)obj).toArray() );
     // Check that filters can be serialized
     obj = doType(conf, new PrefixFilter(HConstants.EMPTY_BYTE_ARRAY),
       PrefixFilter.class);
@@ -94,4 +113,5 @@
     dis.close();
     return product;
   }
+ 
 }
\ No newline at end of file



Mime
View raw message