hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject svn commit: r793472 - in /hadoop/hbase/trunk_on_hadoop-0.18.3: CHANGES.txt src/java/org/apache/hadoop/hbase/client/Scan.java src/test/org/apache/hadoop/hbase/TestSerialization.java
Date Mon, 13 Jul 2009 07:05:47 GMT
Author: apurtell
Date: Mon Jul 13 07:05:46 2009
New Revision: 793472

URL: http://svn.apache.org/viewvc?rev=793472&view=rev
Log:
HBASE-1646

Modified:
    hadoop/hbase/trunk_on_hadoop-0.18.3/CHANGES.txt
    hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/Scan.java
    hadoop/hbase/trunk_on_hadoop-0.18.3/src/test/org/apache/hadoop/hbase/TestSerialization.java

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/CHANGES.txt?rev=793472&r1=793471&r2=793472&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/CHANGES.txt (original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/CHANGES.txt Mon Jul 13 07:05:46 2009
@@ -257,6 +257,7 @@
    HBASE-1644  Result.row is cached in getRow; this breaks MapReduce
                (Doğacan Güney via Stack)
    HBASE-1639  clean checkout with empty hbase-site.xml, zk won't start
+   HBASE-1646  Scan-s can't set a Filter (Doğacan Güney via Stack)
 
   IMPROVEMENTS
    HBASE-1089  Add count of regions on filesystem to master UI; add percentage

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/Scan.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/Scan.java?rev=793472&r1=793471&r2=793472&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/Scan.java
(original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/java/org/apache/hadoop/hbase/client/Scan.java
Mon Jul 13 07:05:46 2009
@@ -25,10 +25,10 @@
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.filter.Filter;
 import org.apache.hadoop.hbase.filter.RowFilterInterface;
-import org.apache.hadoop.hbase.io.HbaseObjectWritable;
 import org.apache.hadoop.hbase.io.TimeRange;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableFactories;
 
 import java.io.DataInput;
 import java.io.DataOutput;
@@ -476,21 +476,31 @@
     return sb.toString();
   }
   
+  @SuppressWarnings("unchecked")
+  private Writable createForName(String className) {
+    try {
+      Class<? extends Writable> clazz =
+        (Class<? extends Writable>) Class.forName(className);
+      return WritableFactories.newInstance(clazz, new Configuration());
+    } catch (ClassNotFoundException e) {
+      throw new RuntimeException("Can't find class " + className);
+    }    
+  }
+  
   //Writable
   public void readFields(final DataInput in)
   throws IOException {
     this.startRow = Bytes.readByteArray(in);
     this.stopRow = Bytes.readByteArray(in);
     this.maxVersions = in.readInt();
-    boolean hasFilter = in.readBoolean();
-    if(hasFilter) {
-      this.filter = (Filter)HbaseObjectWritable.readObject(in,
-        new Configuration());
-    }
-    boolean hasOldFilter = in.readBoolean();
-    if (hasOldFilter) {
-      this.oldFilter = (RowFilterInterface)HbaseObjectWritable.readObject(in,
-          new Configuration());
+    if(in.readBoolean()) {
+      this.filter = (Filter)createForName(Bytes.toString(Bytes.readByteArray(in)));
+      this.filter.readFields(in);
+    }
+    if (in.readBoolean()) {
+      this.oldFilter =
+        (RowFilterInterface)createForName(Bytes.toString(Bytes.readByteArray(in)));
+      this.oldFilter.readFields(in);
     }
     this.tr = new TimeRange();
     tr.readFields(in);
@@ -518,15 +528,15 @@
       out.writeBoolean(false);
     } else {
       out.writeBoolean(true);
-      HbaseObjectWritable.writeObject(out, this.filter, 
-          Filter.class, null);
+      Bytes.writeByteArray(out, Bytes.toBytes(filter.getClass().getName()));
+      filter.write(out);
     }
     if (this.oldFilter == null) {
       out.writeBoolean(false);
     } else {
       out.writeBoolean(true);
-      HbaseObjectWritable.writeObject(out, this.oldFilter,
-          RowFilterInterface.class, null);
+      Bytes.writeByteArray(out, Bytes.toBytes(oldFilter.getClass().getName()));
+      oldFilter.write(out);
     }
     tr.write(out);
     out.writeInt(familyMap.size());

Modified: hadoop/hbase/trunk_on_hadoop-0.18.3/src/test/org/apache/hadoop/hbase/TestSerialization.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk_on_hadoop-0.18.3/src/test/org/apache/hadoop/hbase/TestSerialization.java?rev=793472&r1=793471&r2=793472&view=diff
==============================================================================
--- hadoop/hbase/trunk_on_hadoop-0.18.3/src/test/org/apache/hadoop/hbase/TestSerialization.java
(original)
+++ hadoop/hbase/trunk_on_hadoop-0.18.3/src/test/org/apache/hadoop/hbase/TestSerialization.java
Mon Jul 13 07:05:46 2009
@@ -22,12 +22,11 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.NavigableSet;
+import java.util.Set;
 
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
@@ -35,6 +34,8 @@
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.RowLock;
 import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.filter.Filter;
+import org.apache.hadoop.hbase.filter.PrefixFilter;
 import org.apache.hadoop.hbase.io.BatchOperation;
 import org.apache.hadoop.hbase.io.BatchUpdate;
 import org.apache.hadoop.hbase.io.Cell;
@@ -44,7 +45,6 @@
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Writables;
 import org.apache.hadoop.io.DataInputBuffer;
-import org.apache.hadoop.io.Writable;
 
 /**
  * Test HBase Writables serializations
@@ -370,6 +370,15 @@
       for(byte[] column : set){
         assertTrue(desSet.contains(column));
       }
+      
+      // Test filters are serialized properly.
+      scan = new Scan(startRow);
+      byte [] prefix = Bytes.toBytes(getName());
+      scan.setFilter(new PrefixFilter(prefix));
+      sb = Writables.getBytes(scan);
+      desScan = (Scan)Writables.getWritable(sb, new Scan());
+      Filter f = desScan.getFilter();
+      assertTrue(f instanceof PrefixFilter);
     }
     
     assertEquals(scan.getMaxVersions(), desScan.getMaxVersions());



Mime
View raw message