hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From la...@apache.org
Subject svn commit: r1567460 - in /hbase/branches/0.96: 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 23:29:35 GMT
Author: larsh
Date: Tue Feb 11 23:29:35 2014
New Revision: 1567460

URL: http://svn.apache.org/r1567460
Log:
HBASE-10485 PrefixFilter#filterKeyValue() should perform filtering on row key (Ted Yu and
LarsH)

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

Modified: hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java?rev=1567460&r1=1567459&r2=1567460&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java
(original)
+++ hbase/branches/0.96/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java
Tue Feb 11 23:29:35 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.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java?rev=1567460&r1=1567459&r2=1567460&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java
(original)
+++ hbase/branches/0.96/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestFilterList.java
Tue Feb 11 23:29:35 2014
@@ -18,20 +18,12 @@
  */
 package org.apache.hadoop.hbase.filter;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInput;
-import java.io.DataInputStream;
-import java.io.DataOutput;
-import java.io.DataOutputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertNull;
 
@@ -263,6 +255,38 @@ 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);
+  }
+
+  /**
    * Test serialization
    * @throws Exception
    */
@@ -308,7 +332,7 @@ public class TestFilterList {
     assertEquals(flist.filterKeyValue(new KeyValue(r2,r2,r2)), ReturnCode.SKIP);
   }
 
-  public static class AlwaysNextColFilter extends FilterBase {
+  private static class AlwaysNextColFilter extends FilterBase {
     public AlwaysNextColFilter() {
       super();
     }



Mime
View raw message