hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1566913 - in /hbase/branches/0.98: hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java
Date Tue, 11 Feb 2014 00:43:39 GMT
Author: tedyu
Date: Tue Feb 11 00:43:38 2014
New Revision: 1566913

URL: http://svn.apache.org/r1566913
Log:
HBASE-10485 PrefixFilter#filterKeyValue() should perform filtering on row key


Modified:
    hbase/branches/0.98/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java
    hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java

Modified: hbase/branches/0.98/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java?rev=1566913&r1=1566912&r2=1566913&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java
(original)
+++ hbase/branches/0.98/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java
Tue Feb 11 00:43:38 2014
@@ -25,6 +25,7 @@ import com.google.protobuf.InvalidProtoc
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.exceptions.DeserializationException;
 import org.apache.hadoop.hbase.protobuf.generated.FilterProtos;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -66,6 +67,12 @@ public class PrefixFilter extends Filter
     return filterRow;
   }
 
+  @Override
+  public ReturnCode filterKeyValue(Cell v) {
+    if (filterRow) return ReturnCode.NEXT_ROW;
+    return ReturnCode.INCLUDE;
+  }
+
   public boolean filterRow() {
     return filterRow;
   }

Modified: hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java?rev=1566913&r1=1566912&r2=1566913&view=diff
==============================================================================
--- hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java
(original)
+++ hbase/branches/0.98/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java
Tue Feb 11 00:43:38 2014
@@ -39,7 +39,9 @@ import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValueUtil;
 import org.apache.hadoop.hbase.SmallTests;
+import org.apache.hadoop.hbase.exceptions.DeserializationException;
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
+import org.apache.hadoop.hbase.filter.Filter.ReturnCode;
 import org.apache.hadoop.hbase.filter.FilterList.Operator;
 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -261,6 +263,52 @@ public class TestFilterList {
   }
 
   /**
+   * When we do a "MUST_PASS_ONE" (a logical 'OR') of the above two filters
+   * we expect to get the same result as the 'prefix' only result.
+   * @throws Exception
+   */
+  public void testFilterListTwoFiltersMustPassOne() throws Exception {
+    byte[] r1 = Bytes.toBytes("Row1");
+    byte[] r11 = Bytes.toBytes("Row11");
+    byte[] r2 = Bytes.toBytes("Row2");
+  
+    FilterList flist = new FilterList(FilterList.Operator.MUST_PASS_ONE);
+    flist.addFilter(new PrefixFilter(r1));
+    flist.filterRowKey(r1, 0, r1.length);
+    assertEquals(flist.filterKeyValue(new KeyValue(r1,r1,r1)), ReturnCode.INCLUDE);
+    assertEquals(flist.filterKeyValue(new KeyValue(r11,r11,r11)), ReturnCode.INCLUDE);
+
+    flist.reset();
+    flist.filterRowKey(r2, 0, r2.length);
+    assertEquals(flist.filterKeyValue(new KeyValue(r2,r2,r2)), ReturnCode.SKIP);
+  
+    flist = new FilterList(FilterList.Operator.MUST_PASS_ONE);
+    flist.addFilter(new AlwaysNextColFilter());
+    flist.addFilter(new PrefixFilter(r1));
+    flist.filterRowKey(r1, 0, r1.length);
+    assertEquals(flist.filterKeyValue(new KeyValue(r1,r1,r1)), ReturnCode.INCLUDE);
+    assertEquals(flist.filterKeyValue(new KeyValue(r11,r11,r11)), ReturnCode.INCLUDE);
+
+    flist.reset();
+    flist.filterRowKey(r2, 0, r2.length);
+    assertEquals(flist.filterKeyValue(new KeyValue(r2,r2,r2)), ReturnCode.SKIP);
+  }
+
+  public static class AlwaysNextColFilter extends FilterBase {
+    public AlwaysNextColFilter() {
+      super();
+    }
+    @Override
+    public ReturnCode filterKeyValue(Cell v) {
+      return ReturnCode.NEXT_COL;
+    }
+    public static AlwaysNextColFilter parseFrom(final byte [] pbBytes)
+        throws DeserializationException {
+      return new AlwaysNextColFilter();
+    }
+  }
+
+  /**
    * Test serialization
    * @throws Exception
    */



Mime
View raw message