HBASE-1828 CompareFilters are broken from client-side

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@814099 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Gray 2009-09-12 01:01:49 +00:00
parent a4ee96d5fd
commit 08b616e926
3 changed files with 43 additions and 3 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -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-<d2v1>-<d3v2>"), Bytes.toBytes("col1-<d2v1>-<d3v2>"),
Bytes.toBytes("col2-<d2v1>-<d3v2>"), Bytes.toBytes("col3-<d2v1>-<d3v2>"),
Bytes.toBytes("col4-<d2v1>-<d3v2>"), Bytes.toBytes("col5-<d2v1>-<d3v2>"),
Bytes.toBytes("col6-<d2v1>-<d3v2>"), Bytes.toBytes("col7-<d2v1>-<d3v2>"),
Bytes.toBytes("col8-<d2v1>-<d3v2>"), Bytes.toBytes("col9-<d2v1>-<d3v2>")
};
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.
*/