Index: hbase-server/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java (revision 1407191) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/filter/PrefixFilter.java (working copy) @@ -50,10 +50,12 @@ } public boolean filterRowKey(byte[] buffer, int offset, int length) { - if (buffer == null || this.prefix == null) + if (buffer == null || this.prefix == null) { return true; - if (length < prefix.length) + } + if (length < prefix.length) { return true; + } // if they are equal, return false => pass row // else return true, filter row // if we are passed the prefix, set flag @@ -69,6 +71,33 @@ return passedPrefix; } + @Override + public ReturnCode filterKeyValue(KeyValue kv) { + if (passedPrefix || this.prefix == null) { + return ReturnCode.SKIP; + } + if (kv.getRowLength() < prefix.length) + return ReturnCode.SEEK_NEXT_USING_HINT; + int cmp = Bytes.compareTo(kv.getBuffer(), kv.getRowOffset(), this.prefix.length, this.prefix, 0, + this.prefix.length); + if(cmp > 0) { + return ReturnCode.SKIP; + } else if (cmp < 0) { + return ReturnCode.SEEK_NEXT_USING_HINT; + } + return ReturnCode.INCLUDE; + } + + @Override + public KeyValue getNextKeyHint(KeyValue kv) { + if (kv.getRowLength() < this.prefix.length + || Bytes.compareTo(kv.getBuffer(), kv.getRowOffset(), this.prefix.length, this.prefix, 0, + this.prefix.length) < 0) { + return KeyValue.createFirstOnRow(prefix); + } + return null; + } + public static Filter createFilterFromArguments(ArrayList filterArguments) { Preconditions.checkArgument(filterArguments.size() == 1, "Expected 1 but got: %s", filterArguments.size()); Index: hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestPrefixFilter.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestPrefixFilter.java (revision 1407191) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestPrefixFilter.java (working copy) @@ -20,16 +20,13 @@ package org.apache.hadoop.hbase.filter; import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.SmallTests; import org.apache.hadoop.hbase.util.Bytes; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.UnsupportedEncodingException; import static org.junit.Assert.*; @@ -91,8 +88,11 @@ } String yahooSite = "com.yahoo.www"; byte [] yahooSiteBytes = Bytes.toBytes(yahooSite); - assertTrue("Failed with character " + - yahooSite, filter.filterRowKey(yahooSiteBytes, 0, yahooSiteBytes.length)); + assertTrue("Failed with character " + yahooSite, + filter.filterRowKey(yahooSiteBytes, 0, yahooSiteBytes.length)); + assertEquals("Failed with character " + yahooSite, + filter.filterKeyValue(new KeyValue(yahooSiteBytes, Long.MAX_VALUE)), + Filter.ReturnCode.SEEK_NEXT_USING_HINT); assertEquals(filter.filterAllRemaining(), lastFilterAllRemaining); }