diff --git a/CHANGES.txt b/CHANGES.txt index 4541963cfe2..895e556dbbe 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -20,6 +20,7 @@ Release 0.21.0 - Unreleased HBASE-1824 [stargate] default timestamp should be LATEST_TIMESTAMP HBASE-1740 ICV has a subtle race condition only visible under high load HBASE-1808 [stargate] fix how columns are specified for scanners + HBASE-1828 CompareFilters are broken from client-side IMPROVEMENTS HBASE-1760 Cleanup TODOs in HTable diff --git a/src/java/org/apache/hadoop/hbase/filter/CompareFilter.java b/src/java/org/apache/hadoop/hbase/filter/CompareFilter.java index e653f9fb03c..49a49ed739e 100644 --- a/src/java/org/apache/hadoop/hbase/filter/CompareFilter.java +++ b/src/java/org/apache/hadoop/hbase/filter/CompareFilter.java @@ -27,7 +27,6 @@ import java.util.Arrays; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.io.HbaseObjectWritable; import org.apache.hadoop.io.ObjectWritable; /** @@ -127,15 +126,17 @@ public abstract class CompareFilter implements Filter { } } + private static final HBaseConfiguration hbc = new HBaseConfiguration(); + public void readFields(DataInput in) throws IOException { compareOp = CompareOp.valueOf(in.readUTF()); comparator = (WritableByteArrayComparable) - HbaseObjectWritable.readObject(in, null); + ObjectWritable.readObject(in, hbc); } public void write(DataOutput out) throws IOException { out.writeUTF(compareOp.name()); ObjectWritable.writeObject(out, comparator, - WritableByteArrayComparable.class, null); + WritableByteArrayComparable.class, hbc); } } diff --git a/src/test/org/apache/hadoop/hbase/client/TestClient.java b/src/test/org/apache/hadoop/hbase/client/TestClient.java index 4d855e97fd7..56f064f8073 100644 --- a/src/test/org/apache/hadoop/hbase/client/TestClient.java +++ b/src/test/org/apache/hadoop/hbase/client/TestClient.java @@ -27,6 +27,10 @@ import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.filter.Filter; +import org.apache.hadoop.hbase.filter.QualifierFilter; +import org.apache.hadoop.hbase.filter.RegexStringComparator; +import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; import org.apache.hadoop.hbase.util.Bytes; public class TestClient extends HBaseClusterTestCase { @@ -60,6 +64,40 @@ public class TestClient extends HBaseClusterTestCase { System.out.println("Done."); } + public void testFilters() throws Exception { + byte [] TABLE = Bytes.toBytes("testFilters"); + HTable ht = createTable(TABLE, FAMILY); + byte [][] ROWS = makeN(ROW, 10); + byte [][] QUALIFIERS = { + Bytes.toBytes("col0--"), Bytes.toBytes("col1--"), + Bytes.toBytes("col2--"), Bytes.toBytes("col3--"), + Bytes.toBytes("col4--"), Bytes.toBytes("col5--"), + Bytes.toBytes("col6--"), Bytes.toBytes("col7--"), + Bytes.toBytes("col8--"), Bytes.toBytes("col9--") + }; + for(int i=0;i<10;i++) { + Put put = new Put(ROWS[i]); + put.add(FAMILY, QUALIFIERS[i], VALUE); + ht.put(put); + } + Scan scan = new Scan(); + scan.addFamily(FAMILY); + Filter filter = new QualifierFilter(CompareOp.EQUAL, + new RegexStringComparator("col[1-5]")); + scan.setFilter(filter); + ResultScanner scanner = ht.getScanner(scan); + int expectedIndex = 1; + for(Result result : ht.getScanner(scan)) { + assertEquals(result.size(), 1); + assertTrue(Bytes.equals(result.raw()[0].getRow(), ROWS[expectedIndex])); + assertTrue(Bytes.equals(result.raw()[0].getQualifier(), + QUALIFIERS[expectedIndex])); + expectedIndex++; + } + assertEquals(expectedIndex, 6); + scanner.close(); + } + /** * Test simple table and non-existent row cases. */