You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2010/02/24 18:10:49 UTC
svn commit: r915874 - in /hadoop/hbase/trunk: CHANGES.txt
core/src/main/java/org/apache/hadoop/hbase/filter/WhileMatchFilter.java
core/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
Author: stack
Date: Wed Feb 24 17:10:48 2010
New Revision: 915874
URL: http://svn.apache.org/viewvc?rev=915874&view=rev
Log:
HBASE-2258 The WhileMatchFilter doesn't delegate the call to filterRow()
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/filter/WhileMatchFilter.java
hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=915874&r1=915873&r2=915874&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Wed Feb 24 17:10:48 2010
@@ -209,6 +209,7 @@
HBASE-2129 ant tar build broken since switch to Ivy (Kay Kay via Stack)
HBASE-2226 HQuorumPeerTest doesnt run because it doesnt start with the word Test
HBASE-2230 SingleColumnValueFilter has an ungaurded debug log message
+ HBASE-2258 The WhileMatchFilter doesn't delegate the call to filterRow()
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable
Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/filter/WhileMatchFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/filter/WhileMatchFilter.java?rev=915874&r1=915873&r2=915874&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/filter/WhileMatchFilter.java (original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/filter/WhileMatchFilter.java Wed Feb 24 17:10:48 2010
@@ -27,7 +27,11 @@
import java.io.DataInput;
/**
- * A wrapper filter that filters everything after the first filtered row.
+ * A wrapper filter that filters everything after the first time false is returned
+ * from any wrapped filters {@link Filter#filterRowKey(byte[], int, int)},
+ * {@link Filter#filterKeyValue(org.apache.hadoop.hbase.KeyValue)},
+ * {@link org.apache.hadoop.hbase.filter.Filter#filterRow()} or
+ * {@link org.apache.hadoop.hbase.filter.Filter#filterAllRemaining()}.
*/
public class WhileMatchFilter implements Filter {
private boolean filterAllRemaining = false;
@@ -49,15 +53,16 @@
filterAllRemaining = filterAllRemaining || value;
}
- public boolean filterRowKey(byte[] buffer, int offset, int length) {
- changeFAR(filter.filterRowKey(buffer, offset, length));
- return filterAllRemaining();
- }
-
public boolean filterAllRemaining() {
return this.filterAllRemaining || this.filter.filterAllRemaining();
}
+ public boolean filterRowKey(byte[] buffer, int offset, int length) {
+ boolean value = filter.filterRowKey(buffer, offset, length);
+ changeFAR(value);
+ return value;
+ }
+
public ReturnCode filterKeyValue(KeyValue v) {
ReturnCode c = filter.filterKeyValue(v);
changeFAR(c != ReturnCode.INCLUDE);
@@ -65,7 +70,9 @@
}
public boolean filterRow() {
- return false;
+ boolean filterRow = this.filter.filterRow();
+ changeFAR(filterRow);
+ return filterRow;
}
public void write(DataOutput out) throws IOException {
Modified: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java?rev=915874&r1=915873&r2=915874&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java (original)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/filter/TestFilter.java Wed Feb 24 17:10:48 2010
@@ -4,7 +4,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HBaseTestCase;
@@ -253,6 +255,93 @@
verifyScanFull(s, Arrays.copyOf(expectedKVs, 6));
}
+
+ /**
+ * Tests the the {@link WhileMatchFilter} works in combination with a
+ * {@link Filter} that uses the
+ * {@link PageFilter#filterRow()} method.
+ *
+ * See HBASE-2258.
+ *
+ * @throws Exception
+ */
+ public void testWhileMatchFilterWithFilterRow() throws Exception {
+ final int pageSize = 4;
+
+ Scan s = new Scan();
+ WhileMatchFilter filter = new WhileMatchFilter(new PageFilter(pageSize));
+ s.setFilter(filter);
+
+ InternalScanner scanner = this.region.getScanner(s);
+ int scannerCounter = 0;
+ while (true) {
+ boolean isMoreResults = scanner.next(new ArrayList<KeyValue>());
+ scannerCounter++;
+
+ if (scannerCounter >= pageSize) {
+ Assert.assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining());
+ }
+ if (!isMoreResults) {
+ break;
+ }
+ }
+ Assert.assertEquals("The page filter returned more rows than expected", pageSize, scannerCounter);
+ }
+
+ /**
+ * Tests the the {@link WhileMatchFilter} works in combination with a
+ * {@link Filter} that uses the
+ * {@link PageFilter#filterRowKey(byte[], int, int)} method.
+ *
+ * See HBASE-2258.
+ *
+ * @throws Exception
+ */
+ public void testWhileMatchFilterWithFilterRowKey() throws Exception {
+ Scan s = new Scan();
+ String prefix = "testRowOne";
+ WhileMatchFilter filter = new WhileMatchFilter(new PrefixFilter(Bytes.toBytes(prefix)));
+ s.setFilter(filter);
+
+ InternalScanner scanner = this.region.getScanner(s);
+ while (true) {
+ ArrayList<KeyValue> values = new ArrayList<KeyValue>();
+ boolean isMoreResults = scanner.next(values);
+ if (!isMoreResults || !Bytes.toString(values.get(0).getRow()).startsWith(prefix)) {
+ Assert.assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining());
+ }
+ if (!isMoreResults) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Tests the the {@link WhileMatchFilter} works in combination with a
+ * {@link Filter} that uses the
+ * {@link PageFilter#filterKeyValue(org.apache.hadoop.hbase.KeyValue)} method.
+ *
+ * See HBASE-2258.
+ *
+ * @throws Exception
+ */
+ public void testWhileMatchFilterWithFilterKeyValue() throws Exception {
+ Scan s = new Scan();
+ WhileMatchFilter filter = new WhileMatchFilter(
+ new SingleColumnValueFilter(FAMILIES[0], QUALIFIERS_ONE[0], CompareOp.EQUAL, Bytes.toBytes("foo"))
+ );
+ s.setFilter(filter);
+
+ InternalScanner scanner = this.region.getScanner(s);
+ while (true) {
+ ArrayList<KeyValue> values = new ArrayList<KeyValue>();
+ boolean isMoreResults = scanner.next(values);
+ Assert.assertTrue("The WhileMatchFilter should now filter all remaining", filter.filterAllRemaining());
+ if (!isMoreResults) {
+ break;
+ }
+ }
+ }
public void testInclusiveStopFilter() throws IOException {